Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
working-directory: packages/fonts
- name: Packages contain what they should
run: |
(cd packages/team && npm pack --dry-run 2>&1 | grep -E "bin/ghdash-team.mjs|components/TeamGrid.astro|templates/team/index.astro")
(cd packages/fonts && npm pack --dry-run 2>&1 | grep -E "bin/ghdash-fonts.mjs|lib/build.mjs|components/FontStyles.astro")
(cd packages/team && npm pack --dry-run 2>&1 | grep -E "bin/gitdash-team.mjs|components/TeamGrid.astro|templates/team/index.astro")
(cd packages/fonts && npm pack --dry-run 2>&1 | grep -E "bin/gitdash-fonts.mjs|lib/build.mjs|components/FontStyles.astro")
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# GHDash plugins
# GitDash plugins

Add-ons for [EmDash](https://github.com/emdash-cms/emdash) sites, including sites on GitHub Pages built with [GHDash](https://github.com/Digital-Defiance/ghdash).
Add-ons for [EmDash](https://github.com/emdash-cms/emdash) sites, including sites on GitHub Pages built with [GitDash](https://github.com/Digital-Defiance/gitdash).

GHDash is now GitDash. The packages were published as `@digitaldefiance/ghdash-team` and `@digitaldefiance/ghdash-fonts` before the rename and are now `@digitaldefiance/gitdash-team` and `@digitaldefiance/gitdash-fonts`. To move a site over, swap the dependency, then change `ghdash-` to `gitdash-` in imports and build scripts. The old command names still work.

| Package | What it does |
| --- | --- |
| [`@digitaldefiance/ghdash-team`](packages/team) | A team page: collection, grid component, department filter and a page per member |
| [`@digitaldefiance/ghdash-fonts`](packages/fonts) | Pick Google Fonts in the studio and host them on your own site |
| [`@digitaldefiance/gitdash-team`](packages/team) | A team page: collection, grid component, department filter and a page per member |
| [`@digitaldefiance/gitdash-fonts`](packages/fonts) | Pick Google Fonts in the studio and host them on your own site |

Both are edited in the studio like any other content, so they work on a static GitHub Pages site. See each package's README for setup. A working example is the [demo site](https://digital-defiance.github.io/GHDash-example/).
Both are edited in the studio like any other content, so they work on a static GitHub Pages site. See each package's README for setup. A working example is the [demo site](https://digital-defiance.github.io/GitDash-example/).

## Development

Expand All @@ -17,7 +19,7 @@ cd packages/fonts && npm test

## Releases

A tag `team-v<version>` or `fonts-v<version>` publishes that package to npm through the workflow in `.github/workflows/publish.yml`. The tag has to match the version in the package's `package.json`. Publishing uses npm trusted publishing, so there is no token. The first version of each package has to be published by hand (`npm publish --access public --provenance=false` from the package folder) before the trusted publisher can be added on npmjs.com (organization `Digital-Defiance`, repository `ghdash-plugins`, workflow `publish.yml`).
A tag `team-v<version>` or `fonts-v<version>` publishes that package to npm through the workflow in `.github/workflows/publish.yml`. The tag has to match the version in the package's `package.json`. Publishing uses npm trusted publishing, so there is no token. The first version of each package has to be published by hand (`npm publish --access public --provenance=false` from the package folder) before the trusted publisher can be added on npmjs.com (organization `Digital-Defiance`, repository `gitdash-plugins`, workflow `publish.yml`).

## License

Expand Down
18 changes: 9 additions & 9 deletions packages/fonts/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# @digitaldefiance/ghdash-fonts
# @digitaldefiance/gitdash-fonts

Choose Google Fonts in the studio and serve them from your own site, for [EmDash](https://github.com/emdash-cms/emdash) and [GHDash](https://github.com/Digital-Defiance/ghdash) sites. It covers the main features of the WordPress plugin Fonts Plugin: font choice, per-element typography, and local hosting so visitors make no requests to Google.
Choose Google Fonts in the studio and serve them from your own site, for [EmDash](https://github.com/emdash-cms/emdash) and [GitDash](https://github.com/Digital-Defiance/gitdash) sites. It covers the main features of the WordPress plugin Fonts Plugin: font choice, per-element typography, and local hosting so visitors make no requests to Google.

## Install

```sh
npm install @digitaldefiance/ghdash-fonts
npx ghdash-fonts init # adds a "fonts" collection with one entry to content/
npm install @digitaldefiance/gitdash-fonts
npx gitdash-fonts init # adds a "fonts" collection with one entry to content/
```

Add the component to your layout's `<head>`, after your other stylesheets:

```astro
---
import FontStyles from "@digitaldefiance/ghdash-fonts/FontStyles.astro";
import FontStyles from "@digitaldefiance/gitdash-fonts/FontStyles.astro";
---
<FontStyles />
```

Run `ghdash-fonts build` before `astro build`:
Run `gitdash-fonts build` before `astro build`:

```json
"build": "... && ghdash-fonts build && astro build && ..."
"build": "... && gitdash-fonts build && astro build && ..."
```

## Use
Expand All @@ -40,15 +40,15 @@ Open the **Fonts** collection in the studio, edit the entry, and commit. The nex
| Adobe Fonts web project ID, Adobe fonts | `abc1def`, `proxima-nova`: list the fonts from Adobe, then use them in the font fields above |
| Other elements | one per line: `selector \| Font family \| weight`, such as `blockquote \| Lora \| 400` |

The CSS variables `--ghdash-body-font` and `--ghdash-heading-font` are also set, for use in your own styles.
The CSS variables `--gitdash-body-font` and `--gitdash-heading-font` are also set, for use in your own styles. The older names `--ghdash-body-font` and `--ghdash-heading-font` still work.

If your theme sets fonts with a more specific selector (a class, for example), the settings above won't override it. Use the "Other elements" field to target that selector.

Values are checked before they are written to the stylesheet. A font name, size, color or selector that doesn't look valid is skipped with a warning in the build log.

## Adobe Fonts

Adobe's licence doesn't allow self-hosting, so fonts from an Adobe web project load from `use.typekit.net`, and visitors make a request to Adobe. Google fonts are still served from your site. Create a web project at fonts.adobe.com, add the domains your site uses, and copy the project ID into "Adobe Fonts web project ID". List the Adobe font names (as shown in the project's CSS, like `proxima-nova`) in "Fonts that come from Adobe". If you already ran `ghdash-fonts init`, run it again to add the two new fields.
Adobe's licence doesn't allow self-hosting, so fonts from an Adobe web project load from `use.typekit.net`, and visitors make a request to Adobe. Google fonts are still served from your site. Create a web project at fonts.adobe.com, add the domains your site uses, and copy the project ID into "Adobe Fonts web project ID". List the Adobe font names (as shown in the project's CSS, like `proxima-nova`) in "Fonts that come from Adobe". If you already ran `gitdash-fonts init`, run it again to add the two new fields.

## Your own font files

Expand Down
10 changes: 0 additions & 10 deletions packages/fonts/bin/ghdash-fonts.mjs

This file was deleted.

10 changes: 10 additions & 0 deletions packages/fonts/bin/gitdash-fonts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env node
// gitdash-fonts init adds a "fonts" collection with one entry to a GitDash site's content/ folder
// gitdash-fonts build downloads the chosen Google Fonts into public/fonts and writes public/fonts/fonts.css
const cmd = process.argv[2];
if (cmd === "init") await import("../lib/init.mjs");
else if (cmd === "build") await import("../lib/build.mjs");
else {
console.error("usage: gitdash-fonts init | build");
process.exit(1);
}
14 changes: 7 additions & 7 deletions packages/fonts/lib/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ async function get(url, binary) {
rmSync(out, { recursive: true, force: true });
const row = findRow();
if (!row) {
console.log("ghdash-fonts: no published entry in the fonts collection, skipping");
console.log("gitdash-fonts: no published entry in the fonts collection, skipping");
process.exit(0);
}
const { settings, warnings } = readSettings(row);
for (const w of warnings) console.warn("ghdash-fonts: WARNING:", w);
for (const w of warnings) console.warn("gitdash-fonts: WARNING:", w);

mkdirSync(out, { recursive: true });
const customDir = "custom-fonts";
Expand All @@ -36,20 +36,20 @@ if (existsSync(customDir)) {
for (const file of readdirSync(customDir)) {
const face = parseCustomFontName(file);
if (!face) {
if (!file.startsWith(".")) console.warn(`ghdash-fonts: WARNING: ${customDir}/${file} is not named like "Family Name-400.woff2" and was skipped`);
if (!file.startsWith(".")) console.warn(`gitdash-fonts: WARNING: ${customDir}/${file} is not named like "Family Name-400.woff2" and was skipped`);
continue;
}
copyFileSync(join(customDir, file), join(out, `custom-${file}`));
custom.push(face);
}
if (custom.length) console.log(`ghdash-fonts: ${custom.length} font file(s) from ${customDir}/`);
if (custom.length) console.log(`gitdash-fonts: ${custom.length} font file(s) from ${customDir}/`);
}
const faces = [];
for (const family of families(settings, custom.map((f) => f.family))) {
let res = await get(googleCssUrl(family, settings.weights));
if (res.status === 400) res = await get(googleCssUrl(family));
if (res.status !== 200) {
console.warn(`ghdash-fonts: WARNING: could not find "${family}" on Google Fonts (HTTP ${res.status}); skipped`);
console.warn(`gitdash-fonts: WARNING: could not find "${family}" on Google Fonts (HTTP ${res.status}); skipped`);
continue;
}
const parsed = parseGoogleCss(res.body).filter((f) => settings.subsets.includes(f.subset));
Expand All @@ -59,7 +59,7 @@ for (const family of families(settings, custom.map((f) => f.family))) {
writeFileSync(join(out, fileName(face)), file.body);
faces.push(face);
}
console.log(`ghdash-fonts: ${family}: ${parsed.length} file(s)`);
console.log(`gitdash-fonts: ${family}: ${parsed.length} file(s)`);
}
writeFileSync(join(out, "fonts.css"), `${adobeImport(settings)}${fontFaceCss(faces)}\n${custom.length ? `${customFaceCss(custom)}\n` : ""}${rulesCss(settings)}\n`);
console.log(`ghdash-fonts: wrote ${out}/fonts.css with ${faces.length} font file(s)`);
console.log(`gitdash-fonts: wrote ${out}/fonts.css with ${faces.length} font file(s)`);
6 changes: 4 additions & 2 deletions packages/fonts/lib/css.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ export function rulesCss(s) {
.join(";");
const out = [];
const root = decl([
["--ghdash-body-font", s.bodyFont && stack(s.bodyFont)],
["--ghdash-heading-font", (s.headingFont || s.bodyFont) && stack(s.headingFont || s.bodyFont)],
...["gitdash", "ghdash"].flatMap((p) => [
[`--${p}-body-font`, s.bodyFont && stack(s.bodyFont)],
[`--${p}-heading-font`, (s.headingFont || s.bodyFont) && stack(s.headingFont || s.bodyFont)],
]),
]);
if (root) out.push(`:root{${root}}`);
const body = decl([
Expand Down
11 changes: 7 additions & 4 deletions packages/fonts/lib/init.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// ghdash-fonts init: adds the "fonts" collection and one entry to content/ through the browser API.
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
// gitdash-fonts init: adds the "fonts" collection and one entry to content/ through the browser API.
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { createRequire } from "node:module";
import { dirname, join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { spawnSync } from "node:child_process";

const bin = resolve("node_modules/@digitaldefiance/ghdash-pages/bin/ghdash-pages.mjs");
// The adapter was called ghdash-pages before the GitDash rename.
const ADAPTERS = ["gitdash-pages", "ghdash-pages"];
const pagesDir = ADAPTERS.map((n) => resolve(`node_modules/@digitaldefiance/${n}`)).find((d) => existsSync(d)) ?? resolve("node_modules/@digitaldefiance/gitdash-pages");
const bin = ADAPTERS.map((n) => join(pagesDir, `bin/${n}.mjs`)).find((f) => existsSync(f));
for (const cmd of ["build-db", "fetch-browser-api", "studio-assets"]) {
const r = spawnSync(process.execPath, [bin, cmd], { stdio: "inherit" });
if (r.status !== 0) process.exit(r.status ?? 1);
}
const require = createRequire(resolve("package.json"));
const sqlite3InitModule = (await import(pathToFileURL(require.resolve("@sqlite.org/sqlite-wasm")).href)).default;
const api = await import(pathToFileURL(resolve("public/studio-api/entry.js")).href);
const studioDir = resolve("node_modules/@digitaldefiance/ghdash-pages/studio");
const studioDir = join(pagesDir, "studio");
const { openDb } = await import(pathToFileURL(join(studioDir, "load-db.js")).href);
const { snapshot, filesFromContent, diffFiles } = await import(pathToFileURL(join(studioDir, "tray.js")).href);

Expand Down
38 changes: 28 additions & 10 deletions packages/fonts/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
{
"name": "@digitaldefiance/ghdash-fonts",
"version": "0.2.0",
"description": "Choose Google Fonts in the studio and serve them from your own site, for EmDash and GHDash.",
"name": "@digitaldefiance/gitdash-fonts",
"version": "0.3.0",
"description": "Choose Google Fonts in the studio and serve them from your own site, for EmDash and GitDash.",
"type": "module",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/Digital-Defiance/ghdash-plugins.git",
"url": "git+https://github.com/Digital-Defiance/gitdash-plugins.git",
"directory": "packages/fonts"
},
"homepage": "https://github.com/Digital-Defiance/ghdash-plugins/tree/main/packages/fonts#readme",
"keywords": ["emdash", "ghdash", "astro", "fonts", "google-fonts"],
"bin": { "ghdash-fonts": "bin/ghdash-fonts.mjs" },
"homepage": "https://github.com/Digital-Defiance/gitdash-plugins/tree/main/packages/fonts#readme",
"keywords": [
"emdash",
"gitdash",
"astro",
"fonts",
"google-fonts"
],
"bin": {
"gitdash-fonts": "bin/gitdash-fonts.mjs",
"ghdash-fonts": "bin/gitdash-fonts.mjs"
},
"exports": {
"./FontStyles.astro": "./components/FontStyles.astro",
"./css": "./lib/css.mjs",
"./package.json": "./package.json"
},
"files": ["bin", "lib", "components", "README.md"],
"scripts": { "test": "node --test test/*.test.mjs" },
"peerDependencies": { "astro": ">=5" }
"files": [
"bin",
"lib",
"components",
"README.md"
],
"scripts": {
"test": "node --test test/*.test.mjs"
},
"peerDependencies": {
"astro": ">=5"
}
}
1 change: 1 addition & 0 deletions packages/fonts/test/css.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test("applies body and heading settings, falling back to the body font for headi
const css = rulesCss(settings);
assert.match(css, /body\{font-family:'Lora',system-ui,sans-serif;font-size:18px\}/);
assert.match(css, /h1,h2,h3,h4,h5,h6\{color:#123456;text-transform:uppercase\}/);
assert.match(css, /--gitdash-heading-font:'Lora'/);
assert.match(css, /--ghdash-heading-font:'Lora'/);
});

Expand Down
14 changes: 7 additions & 7 deletions packages/team/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# @digitaldefiance/ghdash-team
# @digitaldefiance/gitdash-team

A team page for [EmDash](https://github.com/emdash-cms/emdash) sites, including sites on GitHub Pages built with [GHDash](https://github.com/Digital-Defiance/ghdash). It is modelled on the features of the WordPress plugin Team Members Pro.
A team page for [EmDash](https://github.com/emdash-cms/emdash) sites, including sites on GitHub Pages built with [GitDash](https://github.com/Digital-Defiance/gitdash). It is modelled on the features of the WordPress plugin Team Members Pro.

You get a `team` collection, a `TeamGrid` component, a `/team` page with department filter buttons, and a page for each member.

## Install

```sh
npm install @digitaldefiance/ghdash-team
npx ghdash-team # adds the "team" collection and three sample members to content/
cp -r node_modules/@digitaldefiance/ghdash-team/templates/team src/pages/team
npm install @digitaldefiance/gitdash-team
npx gitdash-team # adds the "team" collection and three sample members to content/
cp -r node_modules/@digitaldefiance/gitdash-team/templates/team src/pages/team
```

`npx ghdash-team` needs a GHDash site (it uses `@digitaldefiance/ghdash-pages` to build the content database). On a regular EmDash site, create the collection in the admin with the fields below instead.
`npx gitdash-team` needs a GitDash site (it uses `@digitaldefiance/gitdash-pages` to build the content database). On a regular EmDash site, create the collection in the admin with the fields below instead.

## Fields

Expand All @@ -34,7 +34,7 @@ A member that isn't published is not shown.

```astro
---
import TeamGrid from "@digitaldefiance/ghdash-team/TeamGrid.astro";
import TeamGrid from "@digitaldefiance/gitdash-team/TeamGrid.astro";
---
<TeamGrid members={members} layout="grid" shape="round" photoPosition="top" filter />
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/usr/bin/env node
// ghdash-team: adds a "team" collection (fields and three sample members) to a GHDash site's content/ folder.
// Run from the site root: npx ghdash-team
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
// gitdash-team: adds a "team" collection (fields and three sample members) to a GitDash site's content/ folder.
// Run from the site root: npx gitdash-team
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { createRequire } from "node:module";
import { dirname, join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { spawnSync } from "node:child_process";

const bin = resolve("node_modules/@digitaldefiance/ghdash-pages/bin/ghdash-pages.mjs");
// The adapter was called ghdash-pages before the GitDash rename.
const ADAPTERS = ["gitdash-pages", "ghdash-pages"];
const pagesDir = ADAPTERS.map((n) => resolve(`node_modules/@digitaldefiance/${n}`)).find((d) => existsSync(d)) ?? resolve("node_modules/@digitaldefiance/gitdash-pages");
const bin = ADAPTERS.map((n) => join(pagesDir, `bin/${n}.mjs`)).find((f) => existsSync(f));
for (const cmd of ["build-db", "fetch-browser-api", "studio-assets"]) {
const r = spawnSync(process.execPath, [bin, cmd], { stdio: "inherit" });
if (r.status !== 0) process.exit(r.status ?? 1);
}
const require = createRequire(resolve("package.json"));
const sqlite3InitModule = (await import(pathToFileURL(require.resolve("@sqlite.org/sqlite-wasm")).href)).default;
const api = await import(pathToFileURL(resolve("public/studio-api/entry.js")).href);
const studioDir = resolve("node_modules/@digitaldefiance/ghdash-pages/studio");
const studioDir = join(pagesDir, "studio");
const { openDb } = await import(pathToFileURL(join(studioDir, "load-db.js")).href);
const { snapshot, filesFromContent, diffFiles } = await import(pathToFileURL(join(studioDir, "tray.js")).href);

Expand Down
Loading
Loading