Skip to content

Commit

Permalink
brand,html,font-weight - allow brand to customize base weight for all…
Browse files Browse the repository at this point in the history
… headings
  • Loading branch information
cscheid committed Sep 30, 2024
1 parent acddc3e commit c9e8fd3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 109 deletions.
15 changes: 0 additions & 15 deletions src/core/brand/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import {
Brand as BrandJson,
BrandFont,
BrandNamedFont,
BrandNamedLogo,
BrandNamedThemeColor,
BrandStringLightDark,
BrandTypography,
BrandTypographyOptions,
} from "../../resources/types/schema-types.ts";

import { mergeConfigs } from "../../core/config.ts";

// we can't programmatically convert typescript types to string arrays,
// so we have to define this manually. They should match `BrandNamedThemeColor` in schema-types.ts

Expand All @@ -38,18 +35,6 @@ export const defaultColorNames: BrandNamedThemeColor[] = [
"link",
];

// emphasis and link do not have font-family key
// could they still refer to with items?
const defaultFontNames: string[] = [
"base",
// "emphasis",
"headings",
// "link",
"monospace",
"monospace-inline",
"monospace-block",
];

const defaultLogoNames: string[] = [
"small",
"medium",
Expand Down
93 changes: 1 addition & 92 deletions src/core/sass/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ProjectContext } from "../../project/types.ts";
import {
BrandFont,
BrandFontBunny,
BrandFontFile,
BrandFontGoogle,
BrandFontWeight,
} from "../../resources/types/schema-types.ts";
Expand Down Expand Up @@ -275,97 +274,6 @@ const brandTypographyBundle = (
return googleFamily;
};

// const resolveBunnyFontFamily = (
// font: BrandFont[],
// ): string | undefined => {
// let bunnyFamily = "";
// for (const _resolvedFont of font) {
// const resolvedFont = _resolvedFont as (BrandFontGoogle | BrandFontBunny);
// if (resolvedFont.source !== "bunny") {
// return undefined;
// }
// const thisFamily = resolvedFont.family;
// if (!thisFamily) {
// continue;
// }
// if (bunnyFamily === "") {
// bunnyFamily = thisFamily;
// } else if (bunnyFamily !== thisFamily) {
// throw new Error(
// `Inconsisent Bunny font families found: ${bunnyFamily} and ${thisFamily}`,
// );
// }
// typographyVariables.push(bunnyFontImportString(resolvedFont));
// }
// if (bunnyFamily === "") {
// return undefined;
// }
// return bunnyFamily;
// };

// const resolveFilesFontFamily = (
// font: BrandFont[],
// ): string | undefined => {
// let filesFamily = "";
// for (const _resolvedFont of font) {
// const resolvedFont = _resolvedFont as BrandFontFile;
// const files = typeof resolvedFont.files === "string"
// ? [resolvedFont.files]
// : resolvedFont.files;
// if (filesFamily === "") {
// filesFamily = resolvedFont.family;
// } else if (filesFamily !== resolvedFont.family) {
// throw new Error(
// `Inconsisent font families found: ${filesFamily} and ${resolvedFont.family}`,
// );
// }
// // we roll our own List monad-like thing here
// let cssRuleEntries: Record<string, string>[] = [{
// // FIXME
// // src: files.map((file) =>
// // `url('${computePath(file)}') format('${fontFileFormat(file)}')`
// // ).join(", "),
// src: "",
// "font-family": `'${resolvedFont.family}'`,
// }];
// const addEntry = (key: string, value: string | string[] | undefined) => {
// if (!value) {
// return;
// }
// if (typeof value === "string") {
// cssRuleEntries = cssRuleEntries.map((entry) => ({
// ...entry,
// [key]: value,
// }));
// } else {
// const newEntries: Record<string, string>[] = [];
// for (const entry of cssRuleEntries) {
// for (const v of value) {
// newEntries.push({
// ...entry,
// [key]: v,
// });
// }
// }
// cssRuleEntries = newEntries;
// }
// };
// addEntry("font-style", resolvedFont.style);
// const weight = Array.isArray(resolvedFont.weight)
// ? resolvedFont.weight.map((x) => String(x))
// : [String(resolvedFont.weight)];
// addEntry("font-weight", weight);

// const cssString = cssRuleEntries.map((entry) => {
// return "@font-face { " + Object.entries(entry).map(([key, value]) =>
// `${key}: ${value}`
// ).join("; ") + "; }";
// }).join("\n");
// typographyImports.push(cssString);
// }
// return filesFamily;
// };

type HTMLFontInformation = { [key: string]: unknown };

type FontKind =
Expand Down Expand Up @@ -427,6 +335,7 @@ const brandTypographyBundle = (
["family", "headings-font-family"],
["line-height", "headings-line-height"],
["weight", "headings-font-weight"],
["weight", "h1h2h3-font-weight"],
["color", "headings-color"],
["style", "headings-font-style"],

Expand Down
4 changes: 2 additions & 2 deletions src/resources/formats/html/bootstrap/_bootstrap-rules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ h2 {
);
margin-top: 2rem;
margin-bottom: 1rem;
font-weight: 600;
font-weight: $h1h2h3-font-weight;
}

h1.title {
Expand All @@ -641,7 +641,7 @@ h2 {
}

h3 {
font-weight: 600;
font-weight: $h1h2h3-font-weight;
}

h3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,5 @@ $table-group-separator-color-lighter: lighten(
) !default;

$bootstrap-version: 5;

$h1h2h3-font-weight: 600 !default;

0 comments on commit c9e8fd3

Please sign in to comment.