-
Notifications
You must be signed in to change notification settings - Fork 7
/
greenwood.config.js
62 lines (51 loc) · 1.84 KB
/
greenwood.config.js
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
import { greenwoodPluginCssModules } from "@greenwood/plugin-css-modules";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { ResourceInterface } from "@greenwood/cli/src/lib/resource-interface.js";
// TODO would be nice to find a better way to solve this problem
// https://github.com/ProjectEvergreen/www.greenwoodjs.dev/issues/125
class ActiveFrontmatterDocsTitleRestorerResource extends ResourceInterface {
constructor() {
super();
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);
}
}
export default {
activeContent: true,
// would be nice if we could customize these plugins, like appending the autolink headings
// https://github.com/ProjectEvergreen/greenwood/issues/1247
markdown: {
plugins: ["@mapbox/rehype-prism", "rehype-slug", "rehype-autolink-headings", "remark-github"],
},
plugins: [
greenwoodPluginCssModules(),
greenwoodPluginImportRaw(),
{
name: "active-frontmatter-docs-title-restorer-resource",
type: "resource",
provider: (compilation) => new ActiveFrontmatterDocsTitleRestorerResource(compilation),
},
],
polyfills: {
importAttributes: ["css", "json"],
},
prerender: true,
};