mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
refactor(docs): copy Used by from README like financial contributors
Drop data/used-by.json and build-used-by.js; build-contributors.js now extracts USED-BY-BEGIN/END to used-by.swig. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -53,7 +53,6 @@ See the [setup guide][setup] for partials, layouts, caching, and other options.
|
||||
|
||||
## Used by
|
||||
|
||||
<!-- generated by npm run build:used-by — edit data/used-by.json -->
|
||||
<!-- USED-BY-BEGIN -->
|
||||
<p align="center" style="line-height: 2.5;">
|
||||
<a href="https://www.11ty.dev/" style="display: inline-block; vertical-align: middle; margin: 8px;"><img src="https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https%3A%2F%2Fwww.11ty.dev%2F&size=128" height="80" style="vertical-align: middle;" alt="Eleventy" title="Eleventy"/></a>
|
||||
@@ -72,7 +71,7 @@ See the [setup guide][setup] for partials, layouts, caching, and other options.
|
||||
</p>
|
||||
<!-- USED-BY-END -->
|
||||
|
||||
Products and projects running on LiquidJS. [Open a PR](https://github.com/harttle/liquidjs/edit/master/data/used-by.json) to add yours.
|
||||
Products and projects running on LiquidJS. [Open a PR](https://github.com/harttle/liquidjs/edit/master/README.md) to add yours.
|
||||
|
||||
## Financial Support
|
||||
|
||||
|
||||
@@ -33,7 +33,9 @@ function transformFinancial (html) {
|
||||
|
||||
const allContributors = transformContributors(extractSection(readme, 'ALL-CONTRIBUTORS-LIST:START', 'ALL-CONTRIBUTORS-LIST:END'))
|
||||
const financialContributors = transformFinancial(extractSection(readme, 'FINANCIAL-CONTRIBUTORS-BEGIN', 'FINANCIAL-CONTRIBUTORS-END'))
|
||||
const usedBy = transformFinancial(extractSection(readme, 'USED-BY-BEGIN', 'USED-BY-END'))
|
||||
|
||||
const outDir = path.join(root, 'docs/themes/navy/layout/partial')
|
||||
fs.writeFileSync(path.join(outDir, 'all-contributors.swig'), allContributors)
|
||||
fs.writeFileSync(path.join(outDir, 'financial-contributors.swig'), financialContributors)
|
||||
fs.writeFileSync(path.join(outDir, 'used-by.swig'), usedBy)
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const readmePath = path.join(root, 'README.md')
|
||||
const dataPath = path.join(root, 'data/used-by.json')
|
||||
const outDir = path.join(root, 'docs/themes/navy/layout/partial')
|
||||
|
||||
const LINK_STYLE = 'display: inline-block; vertical-align: middle; margin: 8px;'
|
||||
const IMG_STYLE = 'vertical-align: middle;'
|
||||
const PER_ROW = 7
|
||||
|
||||
function escapeHtml (str) {
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
}
|
||||
|
||||
function websiteFavicon (url) {
|
||||
return 'https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=' +
|
||||
encodeURIComponent(url) +
|
||||
'&size=128'
|
||||
}
|
||||
|
||||
async function githubAvatar (url) {
|
||||
try {
|
||||
const { hostname, pathname } = new URL(url)
|
||||
if (hostname !== 'github.com') return
|
||||
const owner = pathname.split('/').filter(Boolean)[0]
|
||||
if (!owner) return
|
||||
const res = await fetch(`https://api.github.com/users/${encodeURIComponent(owner)}`, {
|
||||
headers: { 'User-Agent': 'liquidjs-build-used-by' }
|
||||
})
|
||||
if (!res.ok) return
|
||||
const data = await res.json()
|
||||
if (!data.avatar_url) return
|
||||
const base = data.avatar_url.split('?')[0]
|
||||
return `${base}?s=128`
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function resolveLogo (entry) {
|
||||
if (entry.logo) return entry.logo
|
||||
const gh = await githubAvatar(entry.url)
|
||||
if (gh) return gh
|
||||
return websiteFavicon(entry.url)
|
||||
}
|
||||
|
||||
function imgTag ({ name, src, width, height, imgStyle }) {
|
||||
const alt = escapeHtml(name)
|
||||
const href = escapeHtml(src)
|
||||
const dims = []
|
||||
if (width) dims.push(`width="${width}"`)
|
||||
if (height) dims.push(`height="${height}"`)
|
||||
else if (!width) dims.push('height="80"')
|
||||
const style = imgStyle ? `${IMG_STYLE}${imgStyle}` : IMG_STYLE
|
||||
return `<img src="${href}" ${dims.join(' ')} style="${style}" alt="${alt}" title="${alt}"/>`
|
||||
}
|
||||
|
||||
function linkTag (entry, logo) {
|
||||
const href = escapeHtml(entry.url)
|
||||
const img = imgTag({
|
||||
name: entry.name,
|
||||
src: logo,
|
||||
width: entry.width,
|
||||
height: entry.height,
|
||||
imgStyle: entry.imgStyle
|
||||
})
|
||||
return ` <a href="${href}" style="${LINK_STYLE}">${img}</a>`
|
||||
}
|
||||
|
||||
async function renderHtml (entries) {
|
||||
const logos = await Promise.all(entries.map(resolveLogo))
|
||||
const links = entries.map((entry, i) => linkTag(entry, logos[i]))
|
||||
const lines = ['<p align="center" style="line-height: 2.5;">']
|
||||
links.forEach((link, i) => {
|
||||
if (i > 0 && i % PER_ROW === 0 && links.length - i > 2) lines.push(' <br/>')
|
||||
lines.push(link)
|
||||
})
|
||||
lines.push('</p>')
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
function transformUsedBy (html) {
|
||||
return html
|
||||
.replace(/<br \/>.*?<\/td>/g, '</a></td>')
|
||||
.replace(/\n/g, '')
|
||||
.replace(/<\/tr>\s*<tr>/g, '')
|
||||
}
|
||||
|
||||
function patchReadme (html) {
|
||||
const readme = fs.readFileSync(readmePath, 'utf8').replace(/\r\n/g, '\n')
|
||||
const begin = '<!-- USED-BY-BEGIN -->'
|
||||
const end = '<!-- USED-BY-END -->'
|
||||
const re = new RegExp(`${begin}[\\s\\S]*?${end}`)
|
||||
if (!re.test(readme)) {
|
||||
throw new Error(`README.md is missing ${begin} … ${end}`)
|
||||
}
|
||||
const next = readme.replace(re, `${begin}\n${html}\n${end}`)
|
||||
fs.writeFileSync(readmePath, next)
|
||||
}
|
||||
|
||||
const entries = JSON.parse(fs.readFileSync(dataPath, 'utf8'))
|
||||
|
||||
async function main () {
|
||||
const html = await renderHtml(entries)
|
||||
patchReadme(html)
|
||||
fs.writeFileSync(path.join(outDir, 'used-by.swig'), transformUsedBy(html))
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{ "name": "Eleventy", "url": "https://www.11ty.dev/" },
|
||||
{ "name": "GitHub Docs", "url": "https://docs.github.com/" },
|
||||
{ "name": "Kibana", "url": "https://www.elastic.co/kibana" },
|
||||
{
|
||||
"name": "Power Pages, Azure API Management developer portal",
|
||||
"url": "https://learn.microsoft.com/en-us/power-pages/"
|
||||
},
|
||||
{
|
||||
"name": "Shopify CLI, Checkout Blocks",
|
||||
"url": "https://www.shopify.com/"
|
||||
},
|
||||
{ "name": "Directus", "url": "https://directus.io/" },
|
||||
{
|
||||
"name": "Builder.io, Mitosis",
|
||||
"url": "https://www.builder.io/"
|
||||
},
|
||||
{ "name": "Pattern Lab", "url": "https://patternlab.io/" },
|
||||
{ "name": "Rock RMS", "url": "https://www.rockrms.com/" },
|
||||
{ "name": "WISMOlabs", "url": "https://wismolabs.com/" },
|
||||
{ "name": "Dropkiq", "url": "https://www.dropkiq.com/" },
|
||||
{
|
||||
"name": "Freshet",
|
||||
"url": "https://chromewebstore.google.com/detail/freshet/mpclplhdencffbilobpcapccnihpelcg",
|
||||
"logo": "https://raw.githubusercontent.com/MattAltermatt/freshet/main/public/icon-128.png"
|
||||
}
|
||||
]
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
"version": "7.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prebuild": "npm --prefix .. run build:contributors && npm --prefix .. run build:used-by",
|
||||
"prebuild": "npm --prefix .. run build:contributors",
|
||||
"build": "hexo generate",
|
||||
"start": "hexo serve",
|
||||
"lint": "eslint .",
|
||||
|
||||
Vendored
+1
-1
@@ -16,7 +16,7 @@ index:
|
||||
description: 'Organizations and individuals who <a href="https://github.com/sponsors/harttle">sponsor LiquidJS</a>. Thank you!'
|
||||
used_by:
|
||||
title: Used by
|
||||
description: 'Products and projects running on LiquidJS. <a href="https://github.com/harttle/liquidjs/edit/master/data/used-by.json">Open a PR</a> to add yours.'
|
||||
description: 'Products and projects running on LiquidJS. <a href="https://github.com/harttle/liquidjs/edit/master/README.md">Open a PR</a> to add yours.'
|
||||
|
||||
playground:
|
||||
title: Playground
|
||||
|
||||
+2
-3
@@ -29,14 +29,13 @@
|
||||
"build:min": "BUNDLES=min rollup -c rollup.config.mjs",
|
||||
"build:umd": "BUNDLES=umd rollup -c rollup.config.mjs",
|
||||
"build:charmap": "./bin/character-gen.js > src/util/character.ts",
|
||||
"build:docs": "run-s build:docs-liquid build:contributors build:used-by build:apidoc build:changelog build:docs-hexo",
|
||||
"build:docs": "run-s build:docs-liquid build:contributors build:apidoc build:changelog build:docs-hexo",
|
||||
"build:docs-liquid": "cross-env BUNDLES=min rollup -c rollup.config.mjs && shx cp dist/liquid.browser.min.js docs/themes/navy/source/js/",
|
||||
"build:contributors": "node bin/build-contributors.js",
|
||||
"build:used-by": "node bin/build-used-by.js",
|
||||
"build:apidoc": "shx rm -rf docs/source/api && typedoc --plugin typedoc-plugin-missing-exports ./src --gitRevision master --out docs/source/api",
|
||||
"build:changelog": "node bin/build-changelog.js",
|
||||
"build:docs-hexo": "cd docs && npm ci && npm run build && shx cp CNAME public/",
|
||||
"docs:dev": "run-s build:docs-liquid build:contributors build:used-by docs:serve",
|
||||
"docs:dev": "run-s build:docs-liquid build:contributors docs:serve",
|
||||
"docs:serve": "cd docs && npm run start"
|
||||
},
|
||||
"bin": {
|
||||
|
||||
Reference in New Issue
Block a user