-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from kitspace/readme-processing-2
More readme fixes
- Loading branch information
Showing
9 changed files
with
165 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,57 @@ | ||
import escape from 'escape-html' | ||
import LinkifyIt from 'linkify-it' | ||
import path from 'node:path' | ||
|
||
import { unified } from 'unified' | ||
import rehypeSanitize from 'rehype-sanitize' | ||
import rehypeStringify from 'rehype-stringify' | ||
import remarkEmoji from 'remark-emoji' | ||
import remarkGfm from 'remark-gfm' | ||
import remarkParse from 'remark-parse' | ||
import remarkRehype from 'remark-rehype' | ||
|
||
import { JobData } from '../jobData.js' | ||
import * as utils from '../utils.js' | ||
|
||
const linkify = new LinkifyIt() | ||
|
||
export default function writeKitspaceYaml( | ||
export default async function writeKitspaceYaml( | ||
job, | ||
{ kitspaceYaml, outputDir }: Partial<JobData>, | ||
) { | ||
const kitspaceYamlJson = path.join(outputDir, 'kitspace-yaml.json') | ||
job.updateProgress({ status: 'in_progress', file: kitspaceYamlJson }) | ||
const KitspaceYamlJsonLinkified = linkifyKitspaceYaml(kitspaceYaml) | ||
|
||
const rendered = await renderKitspaceYamlSummaries(kitspaceYaml) | ||
|
||
return utils | ||
.writeFile(kitspaceYamlJson, JSON.stringify(KitspaceYamlJsonLinkified, null, 2)) | ||
.writeFile(kitspaceYamlJson, JSON.stringify(rendered, null, 2)) | ||
.then(() => job.updateProgress({ status: 'done', file: kitspaceYamlJson })) | ||
.catch(error => | ||
job.updateProgress({ status: 'failed', file: kitspaceYamlJson, error }), | ||
) | ||
} | ||
|
||
function linkifyKitspaceYaml(kitspaceYaml) { | ||
async function renderKitspaceYamlSummaries(kitspaceYaml) { | ||
if (kitspaceYaml.multi) { | ||
const linkifiedKitspaceYaml = kitspaceYaml | ||
Object.keys(kitspaceYaml.multi).forEach(subProject => { | ||
linkifiedKitspaceYaml.multi[subProject] = linkifyProjectSummary(kitspaceYaml.multi[subProject]) | ||
}) | ||
return linkifiedKitspaceYaml | ||
} | ||
|
||
return linkifyProjectSummary(kitspaceYaml) | ||
} | ||
|
||
function linkifyProjectSummary(kitspaceYaml) { | ||
let escapedSummary = escape(kitspaceYaml.summary || '') | ||
const matches = linkify.match(escapedSummary) | ||
|
||
if (matches) { | ||
for (const match of matches) { | ||
// Use https by default | ||
const url = new URL(match.url) | ||
if (!match.schema) { | ||
url.protocol = 'https:' | ||
const rendered = { multi: {} } | ||
for (const key of Object.keys(kitspaceYaml.multi)) { | ||
const subProject = kitspaceYaml.multi[key] | ||
rendered.multi[key] = { | ||
...subProject, | ||
summary: await renderSummary(subProject.summary), | ||
} | ||
|
||
escapedSummary = escapedSummary.replace( | ||
match.raw, | ||
`<a href="${url.toString()}" rel="noopener noreferrer" target="_blank">${match.text}</a>` | ||
) | ||
} | ||
return rendered | ||
} | ||
return { ...kitspaceYaml, summary: await renderSummary(kitspaceYaml.summary) } | ||
} | ||
|
||
kitspaceYaml.summary = escapedSummary | ||
return kitspaceYaml | ||
const Remarker = unified() | ||
.use(remarkParse) | ||
.use(remarkEmoji) | ||
.use(remarkGfm) | ||
.use(remarkRehype) | ||
.use(rehypeSanitize) | ||
.use(rehypeStringify) | ||
|
||
async function renderSummary(summary = ''): Promise<string> { | ||
const rendered = await Remarker.process(summary) | ||
return String(rendered) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1125,6 +1125,11 @@ emoji-regex@^8.0.0: | |
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" | ||
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== | ||
|
||
emoticon@^4.0.0: | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/emoticon/-/emoticon-4.0.1.tgz#2d2bbbf231ce3a5909e185bbb64a9da703a1e749" | ||
integrity sha512-dqx7eA9YaqyvYtUhJwT4rC1HIp82j5ybS1/vQ42ur+jBe17dJMwZE4+gvL1XadSFfxaPFFGt3Xsw+Y8akThDlw== | ||
|
||
encodeurl@~1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" | ||
|
@@ -2314,13 +2319,6 @@ lie@~3.3.0: | |
dependencies: | ||
immediate "~3.0.5" | ||
|
||
linkify-it@^4.0.1: | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-4.0.1.tgz#01f1d5e508190d06669982ba31a7d9f56a5751ec" | ||
integrity sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw== | ||
dependencies: | ||
uc.micro "^1.0.1" | ||
|
||
locate-path@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" | ||
|
@@ -3036,6 +3034,13 @@ node-cleanup@^2.1.2: | |
resolved "https://registry.yarnpkg.com/node-cleanup/-/node-cleanup-2.1.2.tgz#7ac19abd297e09a7f72a71545d951b517e4dde2c" | ||
integrity sha1-esGavSl+Caf3KnFUXZUbUX5N3iw= | ||
|
||
node-emoji@^1.11.0: | ||
version "1.11.0" | ||
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.11.0.tgz#69a0150e6946e2f115e9d7ea4df7971e2628301c" | ||
integrity sha512-wo2DpQkQp7Sjm2A0cq+sN7EHKO6Sl0ctXeBdFZrL9T9+UywORbufTcTZxom8YqpLQt/FqNMUkOpkZrJVYSKD3A== | ||
dependencies: | ||
lodash "^4.17.21" | ||
|
||
[email protected]: | ||
version "2.6.7" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" | ||
|
@@ -3521,6 +3526,15 @@ rehype-stringify@^9.0.3: | |
hast-util-to-html "^8.0.0" | ||
unified "^10.0.0" | ||
|
||
remark-emoji@^3.0.2: | ||
version "3.0.2" | ||
resolved "https://registry.yarnpkg.com/remark-emoji/-/remark-emoji-3.0.2.tgz#786e88af1ecae682d74d7e1219989f34708205da" | ||
integrity sha512-hEgxEv2sBtvhT3tNG/tQeeFY3EbslftaOoG14dDZndLo25fWJ6Fbg4ukFbIotOWWrfXyASjXjyHT+6n366k3mg== | ||
dependencies: | ||
emoticon "^4.0.0" | ||
node-emoji "^1.11.0" | ||
unist-util-visit "^4.1.0" | ||
|
||
remark-gfm@^3.0.1: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/remark-gfm/-/remark-gfm-3.0.1.tgz#0b180f095e3036545e9dddac0e8df3fa5cfee54f" | ||
|
@@ -4046,11 +4060,6 @@ typescript@^4.5.5: | |
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" | ||
integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== | ||
|
||
uc.micro@^1.0.1: | ||
version "1.0.6" | ||
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" | ||
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== | ||
|
||
unbox-primitive@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471" | ||
|
@@ -4138,7 +4147,7 @@ unist-util-visit@^3.0.0: | |
unist-util-is "^5.0.0" | ||
unist-util-visit-parents "^4.0.0" | ||
|
||
unist-util-visit@^4.0.0, unist-util-visit@^4.1.1: | ||
unist-util-visit@^4.0.0, unist-util-visit@^4.1.0, unist-util-visit@^4.1.1: | ||
version "4.1.1" | ||
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-4.1.1.tgz#1c4842d70bd3df6cc545276f5164f933390a9aad" | ||
integrity sha512-n9KN3WV9k4h1DxYR1LoajgN93wpEi/7ZplVe02IoB4gH5ctI1AaF2670BLHQYbwj+pY83gFtyeySFiyMHJklrg== | ||
|