-
-
Notifications
You must be signed in to change notification settings - Fork 0
Build plugins docs during the website build #42
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
Changes from all commits
38e3d2d
22c15ac
c0e0b29
092a2be
69374f8
a2caf01
8b81b3e
891be35
5112c08
cd7283d
0ffbf21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ Thumbs.db | |
| # Generated files | ||
| *.html | ||
| api | ||
| plugins | ||
|
|
||
| # Cache | ||
| .cache | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,4 @@ | ||
| { | ||
| "layout": "home.njk", | ||
| "resources": [ | ||
| "https://plugins.prismjs.com/keep-markup/prism-keep-markup.js", | ||
| "https://dev.prismjs.com/components/prism-bash.js" | ||
| ] | ||
| "resources": ["plugins/keep-markup/prism-keep-markup.js", "https://dev.prismjs.com/components/prism-bash.js"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import fs from "fs/promises"; | ||
| import path from "path"; | ||
| import { fileURLToPath } from "url"; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| const sourcePath = path.resolve(__dirname, "../node_modules/prismjs/src/plugins"); | ||
| const destPath = path.resolve(__dirname, "../plugins"); | ||
|
|
||
| async function copy () { | ||
| // We need { recursive: true } so the script doesn't fail if the folder already exists | ||
| await fs.mkdir(destPath, { recursive: true }); | ||
|
|
||
| let plugins = await fs.readdir(sourcePath, { withFileTypes: true }); | ||
| for (let plugin of plugins) { | ||
| if (!plugin.isDirectory()) { | ||
| continue; | ||
| } | ||
|
|
||
| let source = path.join(sourcePath, plugin.name); | ||
| let dest = path.join(destPath, plugin.name); | ||
| await fs.mkdir(dest, { recursive: true }); | ||
|
|
||
| let files = await fs.readdir(source, { withFileTypes: true }); | ||
| for (let file of files) { | ||
| if (!file.isFile()) { | ||
| continue; | ||
| } | ||
|
|
||
| let name = path.parse(file.name).name; | ||
| // Copy only the README.md and demo.* files | ||
| if (["README", "demo"].includes(name)) { | ||
| await fs.copyFile(path.join(source, file.name), path.join(dest, file.name)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| await copy(); | ||
|
|
||
| // Create plugins.json in the plugins folder with global data | ||
| let json = { | ||
| permalink: "{{ page.filePathStem.replace('README', '/index') }}.html", | ||
| tags: ["plugin"], | ||
| }; | ||
|
|
||
| await fs.writeFile(path.join(destPath, "plugins.json"), JSON.stringify(json, null, "\t")); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Do not redirect | ||
| /plugins/:plugin/index.html /plugins/:plugin/index.html 200 | ||
| /plugins/:plugin/demo.html /plugins/:plugin/demo.html 200 | ||
| /plugins/:plugin/demo.js /plugins/:plugin/demo.js 200 | ||
| /plugins/:plugin/demo.css /plugins/:plugin/demo.css 200 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused, these seem to be redirecting to themselves?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No wonder. This looks weird, I agree. The following redirect rule also covers these cases, but we don't want to redirect those files (they live in the website repo). Due to limitations of the ChatGPT says we can try Netlify Edge functions for this. I haven't tried it yet, but I will probably do so in the next iteration. |
||
|
|
||
| # Components: languages, themes, plugins, etc. | ||
| /components/* https://dev.prismjs.com/components/:splat 200 | ||
| /plugins/:plugin/:file https://dev.prismjs.com/plugins/:plugin/:file 301 | ||
|
|
||
| # Make the autoloader plugin work | ||
| /plugins/:plugin/components/* https://dev.prismjs.com/components/:splat 301 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to do this? I would expect 11ty's regular collections to work just fine if we apply good tags etc (which we can do at the directory level).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still depend on this when building a list of supported languages on the main page and a list of languages and themes that might be included in a bundle on the Download page.
I'm planning to ditch it in the following PRs. I didn't want to work on this in this PR since it seems orthogonal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. And yes, we can eventually ditch it. For plugins, we already have their readmes that should contain all their metadata as 11ty data. For languages, that would be too heavyweight, so we could follow a mixed approach: Declare their metadata at the top of the file using a doc comment (that is then picked up by our build process), and have MD files for those that want to declare more details. Then, our build tool produces MD files for the rest. These pages should also host the examples for each language, which are currently a separate app with questionable UX where you select the languages you want to see examples of via checkboxes (which seems clever, but is not how anyone looks for examples of certain languages, so it just becomes a hassle)