-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgreenwood.config.js
More file actions
77 lines (67 loc) · 2.31 KB
/
greenwood.config.js
File metadata and controls
77 lines (67 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { greenwoodPluginCssModules } from "@greenwood/plugin-css-modules";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { greenwoodPluginMarkdown } from "@greenwood/plugin-markdown";
// TODO would be nice to find a better way to solve this problem
// https://github.com/ProjectEvergreen/www.greenwoodjs.dev/issues/125
/** @type {import('@greenwood/cli').ResourcePlugin} */
class ActiveFrontmatterDocsTitleRestorerResource {
constructor() {
this.extensions = ["html"];
this.contentType = "text/html";
this.matches = ["My Blog - Active Frontmatter", "My Site - Going Further"];
this.replacer = "${globalThis.page.title}";
}
async shouldIntercept(url, request, response) {
return response.headers.get("Content-Type")?.indexOf(this.contentType) >= 0;
}
async intercept(url, request, response) {
let body = await response.text();
this.matches.forEach((match) => {
if (body.indexOf(match) > 0) {
const titleParts = match.split("-");
body = body.replace(
new RegExp(String.raw`${match}`, "g"),
`${titleParts[0]}- ${this.replacer}`,
);
}
});
return new Response(body);
}
}
/** @type {import('@greenwood/cli').Config} */
export default {
activeContent: true,
plugins: [
greenwoodPluginMarkdown({
plugins: [
"@mapbox/rehype-prism",
"rehype-slug",
"rehype-autolink-headings",
"remark-github",
"remark-gfm",
{
name: "rehype-external-links",
options: {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#security_and_privacy
rel: ["nofollow", "noopener", "noreferrer"],
target: "_blank",
contentProperties: { className: ["no-show-screen-reader"] },
content: [{ type: "text", value: " (opens in a new window)" }],
properties: { className: ["external-link-icon"] },
},
},
],
}),
greenwoodPluginCssModules(),
greenwoodPluginImportRaw(),
{
name: "active-frontmatter-docs-title-restorer-resource",
type: "resource",
provider: (compilation) => new ActiveFrontmatterDocsTitleRestorerResource(compilation),
},
],
polyfills: {
importAttributes: ["css", "json"],
},
prerender: true,
};