Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
19 changes: 0 additions & 19 deletions .github/workflows/plugins-website-rebuild.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Thumbs.db
# Generated files
*.html
api
plugins

# Cache
.cache
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ Couldn’t find the language you were looking for? [Request it](https://github.c
Plugins are additional scripts (and CSS code) that extend Prism’s functionality. Many of the following plugins are official, but are released as plugins to keep the Prism Core small for those who don’t need the extra functionality.

<ul class="plugin-list">
{% for id, plugin in plugins -%}
{% for plugin in collections.plugin -%}
{%- set meta = plugin.data -%}
<li>
<a href="https://plugins.prismjs.com/{{ id }}">{{ plugin.title }}</a>
<div>{{ plugin.description | safe }}</div>
<a href="plugins/{{ meta.id }}">{{ meta.title | md }}</a>
<div>{{ meta.description | md }}</div>
</li>
{% endfor -%}
</ul>
Expand Down
47 changes: 47 additions & 0 deletions _build/copy-plugins.mjs
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

Copy link
Copy Markdown
Member

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.md and demo.*?

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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

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"));
5 changes: 4 additions & 1 deletion _build/eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };

Copy link
Copy Markdown
Member

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).

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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)


/** @param {import("@11ty/eleventy").UserConfig} config */
export default config => {
Expand Down Expand Up @@ -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"],
Expand Down
37 changes: 29 additions & 8 deletions _data/eleventyComputed.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
export default {
components (data) {
let components = { ...data.components };
components.plugins = { ...(data.pluginsWithMeta ?? {}) };
return components;
},
plugins (data) {
let plugins = { ...data.pluginsWithMeta };
delete plugins.meta;
return plugins;
return { ...data.components };
},
themes (data) {
let themes = { ...data.components.themes };
Expand All @@ -29,6 +22,14 @@ export default {

return languages;
},
// Plugin id
id (data) {
let parts = data.page.inputPath.slice(2).split("/");
if (parts[0] === "plugins") {
// Folder name ↔ plugin id
return parts[1];
}
},
title (data) {
if (data.title) {
return data.title;
Expand All @@ -46,6 +47,26 @@ export default {

return title[0].toUpperCase() + title.slice(1);
},
resources (data) {
let { id, resources = [] } = data;
let ret = [];

resources = Array.isArray(resources) ? resources : [resources];
ret.push(...resources);

if (!id) {
return ret;
}

// We are working with plugin resources
ret.push(`./prism-${id}.js { type="module" }`);

if (!data.noCSS) {
ret.push(`./prism-${id}.css`);
}

return ret;
},
files_sizes (data) {
let ret = {};
for (let file of data.tree) {
Expand Down
16 changes: 0 additions & 16 deletions _data/pluginsWithMeta.js

This file was deleted.

10 changes: 10 additions & 0 deletions _redirects
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
11 changes: 11 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,14 @@ ul.plugin-list {
border-bottom-left-radius: 0;
}
}

/* Decorate only the first link in headings */
section :is(h1, h2, h3)[id] {
a:not(:first-of-type) {
text-decoration: revert;

&::before {
display: none;
}
}
}
9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "The website of prismjs.com",
"type": "module",
"scripts": {
"postinstall": "node _build/copy-plugins.mjs",
"dependencies": "npm install --prefix node_modules/prismjs",
"dev": "netlify dev -p 8844",
"serve": "npx @11ty/eleventy --config=_build/eleventy.js --serve --quiet",
Expand Down