Code Monkey home page Code Monkey logo

specimen-skeleton's Introduction

Specimen Skeleton

Project setup & development

This project requires Node.js >= 12 and yarn.

To get started, run the following commands from the root of the repo:

  • yarn install
  • yarn fontdata - this will generate data files for the fonts in src/fonts
  • yarn start - this will start the local development server, view at http://localhost:8080.

The site will automatically be re-built and deployed on Github Pages every time the master branch is updated.

Specimen Skeleton uses external tooling from Specimen Skeleton Support, so we can add or update features without you having to update your specimen!

What this is

Specimen Skeleton is an Eleventy-based specimen boilerplate. It helps you get a basic site up and running quickly, and offers you a few interactive elements to build your demos from.

It will analyse your variable font and generate the CSS necessary and all the sliders, so you'll hit the ground running!

What this isn't

A full-blown specimen generator like Specimen Tools. We did some groundwork, but it's up to you to build the site!

Checklist / getting started

  • Put your WOFF2 fonts in src/fonts and run yarn fontdata.
  • Configure the site in src/_data/site.js.
  • In JavaScript, respond to fail/success of loading the font in the FontFaceObserver code.
  • In HTML/CSS, use the .variable-support element to communicate when variable fonts aren't supported.
  • Start/stop heavy animations by using the .am-i-in-view and .in-view classes.

On using fonts

You have two variables at your disposal, which will be generated when you run yarn fontdata. See the templates for some example on how to use them.

fontdata

The fontdata variable containsall metadata from _data/fontdata.json. This file contains a list of all the fonts found in src/fonts, and offers the following variables per font:

name, containing the font name (e.g. Bungee Regular) selector, the CSS selector to apply the font (e.g. bungee-regular) style, the suggested style of this font (e.g. regular)

You can change the order of these fonts, so the font family tree makes sense when you loop over them in the specimen (e.g. light weights first, bold weights last). You can also rename the suggested style, which Specimen Skeleton tries to derive from the tfilename. You shouldn't change the selector though โ€” this is used to apply the font in CSS, and to pick fonts from the fonts variable.

You can specify which font is the "main" font (usually the "regular" style), by assigning its ID to the main_id variable. Note that counting starts at 0!

fonts

The Specimen Skeleton loops over all fonts, and presents an object for each font with all data from the relevant src/_data files. This font variable contains its charset, variable axes and variable instances. You can address these by their selector from the fontdata variable:

{{ fonts["bungee-regular"].charset }}

On using assets

In HTML, to use an image from your img directory, use the following URL value with the relative path to your image:

<img src="{% webpackAssetPath '../img/my_logo.svg' %}">

If you want to inline an SVG image, use:

{% include '../img/my_logo.svg' %}

or

{% webpackAssetContents 'img/my_logo.svg' %}

In CSS, point to the file using the path relative to your CSS file:

background-image: url(../img/my_logo.svg);

In CSS, images below 8 KB will be inlined automatically. To force inlined or external, append ?inline or ?external respectively, e.g. url(../img/my_logo.svg?external);. Inlining in HTML files

Components

The boilerplate has some very basic components you can base your specimen site on:

Interactive Controls

Basic setup to have interactive axis sliders, as well as a dropdown with named instances. All elements with the class .interactive-controls-text inside the parent container .interactive-controls will respond to changes.

Character Grid

Simple grid to show all characters in the font. On hover, the character will be shown in a separate div.

Am I in view?

Simple example to stop CPU-melting animations when they're not in the viewport. Elements with the class .am-i-in-view will get a class .in-view when they're in the viewport, and have that class removed when they leave the viewport. Use this to start/stop heavy animations.

Note: this can be repurposed for lazy loading images, pausing video, etc.

Stuff made with Specimen Skeleton

specimen-skeleton's People

Contributors

dependabot[bot] avatar pascalw avatar roeln avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

specimen-skeleton's Issues

Easier access to, and more control of font data

Accessing multiple fonts is cumbersome in the current setup. Also, order of fonts is not guaranteed because of the nondeterministic way 11ty processes _data files:

The non deterministic order seems to be caused by 11ty. 11ty adds global data files to the global data file in an non-deterministic order. Even if it didn't, relying on ordering of object keys is not very safe. So best is probably to generate a list of fonts somewhere, where we control the order of that list.

@pascalw proposes this:

Generate src/fonts/meta.json and fill it:

{
  "fonts": [
    {
       "name": "font one",
       "selector": "font-one"
    },
    {
       "name": "font two",
       "selector": "font-two"
    },
  ]
}

Then we can avoid generating fonts.js, as this JSON can directly imported instead via Webpack, giving us access to the same data we need. An author can tweak the order of fonts by editing the meta.json file. We'd also be able to work with arrays instead of objects, further simplifying things.

Generate multiple specimens when multiple families are supplied

Instead of generating a single specimen, allow the build process to take multiple directories of fonts and build a single specimen for each one.

Combined with a --watch parameter, relevant specimens would auto-update whenever one of their fonts changes. So you'd always have an up-to-date "specimen archive"

localhost:1234 Homepage with links to all fonts
localhost:1234/recursive Recursive Variable Specimen Page
localhost:1234/bungee Bungee Specimen Page
etc.

Enforce uniform class names

Currently using snake-case, based on personal preference. Would be great if the linter caught deviations.

(Bonus would be if you could config your own preference so folks could easily switch to camelCase, BEM, etc.)

Refactor data generation

Do not mutate files, but write them once all data is gathered (see #58 (comment))

(Optionally, clear out _data dir before generating new fonts, so as to not confuse the site that's being built with old fonts.

Do not offer font in repo, but offer "example build"

Preferably I'd keep the code clean of anything related to an actual font. So folks would have to check out the repo, add a font, build the site.

Maybe just clean up #28 and add instructions? "Check our repo, download and store a font in this dir, run the yarn stuff"

Generate more data about font

There's many more things we can extract from the font. Users now manually add this info, as is done here (private repo at the moment).

We could hook this up to the Wakamai Fondue Engine and generate controls for layout features, localization, language support etc.

Fill in more font details after generating data

After running node _tools/generateFontData.js we should:

  • Fill font family name in styles for body (font-family: example-font, monospace;)
  • Fill in axes in :root and * declarations
  • Fill in const fontName = "..."; in main.js

Handle (non-variable) font families

E.g.

MyFont-Bold.woff2
MyFont-Light.woff2
MyFont-Regular.woff2
MyFont-Condensed.woff2

Will be seen as four fonts. It's up to the author to create a proper dropdown to choose between these weights/styles.

We should have some user-definable mapping so we can fill that dropdown better, in an order we decide. Something like:

Weight dropdown
MyFont-Light = Light
MyFont-Regular = Regular
MyFont-Bold. = Bold

Handle multiple fonts in `src/fonts`

  • Create JS data for FontFaceObserver so it will observe multiple fonts
  • Create stylesheet with multiple fonts
  • Split up CSS variables and font-family stuff (note to self: re-setting CSS variables on each elements is bad!)
  • Generate all elements in the side per font, instead of just once

(Breaking) changes

  • Font is not applied side-wide, but should be applied "locally" on elements by their classname

Group glyphs by type

@markboulton suggested

The current glyph table dumps all characters sequentially; it would be better to group glyphs by type, as is often done in specimens.

@RoelN said,

I had a quick look at grouping those characters by type. It looks like Unicode categories aren't directly usable. For instance, the "Currency Symbols"-block doesn't contain the $.

The "Character Viewer" on Mac has a better categorisation, maybe we can tap into that and refine as needed

Alternatively we can look at groupings in existing specimens. Some of that can be automated, but it'd be a mostly manual process. (I would be interested in such a list for Wakamai Fondue myself, by the way! Beats a "dumb character dump")

It seems to me that a good source of such glyph metadata, libre licensed, is https://github.com/schriftgestalt/GlyphsInfo/blob/master/GlyphData.xml which is fully documented at https://glyphsapp.com/tutorials/roll-your-own-glyph-data and there's a freeware macOS app https://glyphsapp.com/tools/editglyphdata for dealing with it, but its standards compliant XML so any editor can do :)

Minification options

It would be awesome if we could:

  • Minify HTML
  • Embed external resources (e.g. "when CSS is less than 8K" or when a custom attribute is set on the script/link elements?)

Animation performance

Variable font animations should be made as performant as possible:

  • Use requestanimationframe when triggering from JS
  • Use Intersection Observer to detect elements in view
  • Debounce/throttle?

Improve script loading

Javascript is now placed just before the </body> tag. Placing it in the head and using either defer or async allows the browser to start downloading the assets earlier.

Do not set weight through variable

We should avoid the --wght variable, and use font-weight instead.

This means the --wght variable doesn't need to be set, and should be removed from the font-variation-settings rule.

Add .nojekyll in deploy task

To disable Jekyll processing by GitHub Pages.

This makes deployments faster and also prevents issues with GitHub Pages trying to process deployments as it if were a Jekyll site, which it isn't.

Rename repo to specimen-skeleton

Specimen boilerplate is to the point, but boring.

Suggestions:

  • Specimen Sketch (refers to sketching, the first step in developing a new typeface)
  • Specimen Skeleton (skeletons are way cooler than "boilerplates") ๐Ÿ’€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.