-
-
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 6 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 |
|---|---|---|
| @@ -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; | ||
| // Don't copy the plugin source files | ||
| if (!name.endsWith(plugin.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")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import markdownItDeflist from "markdown-it-deflist"; | |
| import pluginTOC from "eleventy-plugin-toc"; | ||
| import * as filters from "./filters.js"; | ||
|
|
||
| import components from "prismjs/src/components.json" with { type: "json" }; | ||
| import components from "../node_modules/prismjs/src/components.json" with { type: "json" }; | ||
|
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. 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).
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. 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.
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. 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) |
||
|
|
||
| /** @param {import("@11ty/eleventy").UserConfig} config */ | ||
| export default config => { | ||
|
|
@@ -72,6 +72,9 @@ export default config => { | |
| ul: true, | ||
| }); | ||
|
|
||
| // Don't ignore the folders that are gitignored (plugins, examples, themes, etc.) | ||
| config.setUseGitIgnore(false); | ||
|
|
||
| return { | ||
| markdownTemplateEngine: "njk", | ||
| templateFormats: ["md", "njk"], | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # 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 | ||
|
|
||
| # Components: languages, themes, plugins, etc. | ||
| /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.
What if instead of excluding files based on heuristics we only include
README.mdanddemo.*?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.
My first attempt was exactly what you proposed. However, later, I realized that plugin docs might depend on other files, such as external stylesheets, scripts, images, data files, etc., and we don't know what names they might have. The only thing we can be sure of, though, is that we don't want to copy the plugin source files whose names happen to end with the plugin ID. So, I decided to follow that route.
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.
They shouldn't though. And if they do, they can always include them via HTML in
README.md. I think it's okay to restrict what plugins can do in their docs a bit if it leads to a more predictable structure and less clutter in the source repo.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.
Oh, okay then. I'll fix it