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

Create a searchable website of formulas similar to Homebew #174

Merged
merged 22 commits into from
Feb 29, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: deploy-pages
on:
push:
branches: "v3"
paths-ignore:
- README.md
- CONTRIBUTING.md
- LICENSE
- .gitignore
- .github/**
- "!.github/workflows/deploy-pages.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
deploy-pages:
environment:
name: github-pages
url: ${{ steps.deploy-pages.outputs.page_url }}
permissions:
pages: write
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: latest
# Lockfile is in subfolder
# cache: npm
- run: npm install
working-directory: docs
- id: configure-pages
uses: actions/configure-pages@v4
- run: npm run build
working-directory: docs
env:
BASE_PATH: ${{ steps.configure-pages.outputs.base_path }}/
- uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
- id: deploy-pages
uses: actions/deploy-pages@v4
5 changes: 5 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# http://help.houndci.com/en/articles/2138473-hound

# http://help.houndci.com/en/articles/2138497-jshint
jshint:
enabled: false
139 changes: 139 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# https://vitepress.dev/
**/.vitepress/cache
**/.vitepress/dist

# Custom pre-build step
/formulas/

#region https://github.com/github/gitignore/blob/main/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
#endregion
59 changes: 59 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { defineConfig } from "vitepress";

// https://vitepress.dev/reference/site-config
export default defineConfig({
ignoreDeadLinks: [
"./www.woowahan.com",
"./www.woowahan.comm",
"./http//scripts.sil.org/OFL",
],

// https://vitepress.dev/guide/routing#generating-clean-url
cleanUrls: true,

title: "Fontist Formulas",
description: "Index of all Fontist Formulas",

// https://github.com/vuejs/vitepress/issues/3508
base: process.env.BASE_PATH,

themeConfig: {
logo: "/logo.png",

// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "Home", link: "/" },
{ text: "Guide", link: "/guide/" },
{ text: "Formulas", link: "/formulas/" },
],

// https://vitepress.dev/reference/default-theme-search
search: {
provider: "local",
},

sidebar: {
"/guide/": [
{
text: "Guide",
items: [
{ text: "Create a Formula", link: "/guide/create-formula" },
{
text: "Private repositories",
link: "/guide/private-repositories",
},
],
},
],
},

socialLinks: [
{ icon: "github", link: "https://github.com/fontist/formulas" },
],

footer: {
message: `Fontist is <a href="https://open.ribose.com/">riboseopen</a>`,
copyright: `Copyright &copy; 2023 Ribose Group Inc. All rights reserved.`,
},
},
});
94 changes: 94 additions & 0 deletions docs/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env node
import * as YAML from "yaml";
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
import { resolve, join, basename, dirname } from "node:path";
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
// import { marked } from 'marked'
import { glob } from "glob";
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

const projectRoot = resolve(process.cwd(), "..");
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

await rm("formulas", { recursive: true, force: true });
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
await mkdir("formulas", { recursive: true });
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

function escapeHTML(html) {
return html
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}

const allFormulas = [];
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

for (const relativeFilePath of await glob("**/*.y{a,}ml", {
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
cwd: join(projectRoot, "Formulas"),
nodir: true,
})) {
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
const absoluteFilePath = join(projectRoot, "Formulas", relativeFilePath);
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
const text = await readFile(absoluteFilePath, "utf8");
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
const yamls = YAML.parseAllDocuments(text).map((x) => x.toJSON());
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
const yaml = yamls.reduce((a, x) => Object.assign(a, x), {});
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
const slug = relativeFilePath.replace(/\.ya?ml$/, "");
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
// const licenseHTML = marked(yaml.requires_license_agreement || "", { breaks: true })
const fontNames = (yaml.fonts ?? [])
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
.flatMap((font) => font.styles ?? [])
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
.map((style) => {
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
if (style.type) {
return `${style.family_name} (${style.type})`;
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
} else {
return style.family_name;
}
});
const githubURL = `https://github.com/fontist/formulas/blob/main/Formulas/${relativeFilePath}`;
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

const name = yaml.name || yaml.description || basename(slug);
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Get the local search to only search specific parts of this
// generated markdown. Namely just the name, description, and list of fonts.
const md = `\
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
---
outline: false
---

# ${name}

${yaml.description || ""}

[📜 View source](${githubURL})

${fontNames.map((font) => `- ${font}`).join("\n")}
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

${escapeHTML(yaml.copyright || "")}

${yaml.license_url ? `[${yaml.license_url}](${yaml.license_url})` : ""}`;
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved

await mkdir(dirname(`formulas/${slug}.md`), { recursive: true });
await writeFile(`formulas/${slug}.md`, md);
// console.log(`Wrote formula/${slug}.md`)

allFormulas.push({
name,
slug,
fontNames,
githubURL,
});
}

const md = `\
---
search: false
outline: false
---

# All Formulas

${allFormulas
.map(
(formula) => `\
- [${formula.name}](/formulas/${formula.slug}) \\
${formula.fontNames.join(", ")}`,
)
.join("\n\n")}
`;
await writeFile(`formulas/index.md`, md);
23 changes: 23 additions & 0 deletions docs/guide/create-formula.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
search: false
---

# Create a Formula

The purpose of a formula is to allow Fontist to determine where to download fonts.

There is a command that can generate a formula by an archive's link:

```sh
fontist create-formula https://quoteunquoteapps.com/courierprime/downloads/courier-prime.zip
```

The result of its execution would be a YAML file. It can be changed with a text editor.

You may need to change it manually when:

- the script could not detect proper license text
- you would like to change a name of a formula (may use the `--name` option)
- the archive is private (see [private-formula-authentication](/guide/private-repositories#private-formula-authentication))

The formula can be proposed to be merged to [the main repository](https://github.com/fontist/formulas), or added to a private repository.
Loading
Loading