Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy-to-access font variable #283

Closed
peterkos opened this issue Dec 19, 2020 · 1 comment
Closed

Easy-to-access font variable #283

peterkos opened this issue Dec 19, 2020 · 1 comment
Labels

Comments

@peterkos
Copy link

It'd be nice if fonts were set via a variable, e.g.:

--font-title: "Fira Sans", sans-serif;
--font-body: "Fira Sans", sans-serif;
--font-nav: "Fira Sans", sans-serif;

(rough list)

Currently, to change the fonts, it's a bit messy:

.post-title, .post-subtitle, .post-nav, .related-title, thead, dt,
.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4,
.post-body h5,
.post-body h6, {
    font-family: "Fira Sans", sans-serif;
}

(And that's only a subset of the selectors!)

@reuixiy
Copy link
Owner

reuixiy commented Dec 20, 2020

Hmmm, the code you pasted here is actually the production version generated by SCSS.

In our codebase, it looks like this:

@if variable-exists("fontFamilyHeadings") {
.post-body {
h1, h2, h3, h4, h5, h6 {
font-family: $fontFamilyHeadings;
}
}
.contents-title {
font-family: $fontFamilyHeadings;
}
}

{{ with .Site.Params.fontFamilyHeadings }}
$fontFamilyHeadings: {{ $glyph }}{{ . }};
{{ end }}

and the value of SCSS variable $fontFamilyHeadings comes from config.toml (via Hugo's resources.ExecuteAsTemplate function)

# Headings, toc title
fontFamilyHeadings = "'Comfortaa', sans-serif"

So it's easy-to-access for users already.

Also, the font-family related code in MemE all categorized into _font-family.scss, which improves the maintainability. Though we might repeat the code a bit (the selectors).

The CSS variables you mentioned here, maybe we can use it to replace the SCSS variables, so that user can easily customize font-familys on browser via JavaScript. But guess that's another new feature for MemE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants