Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
510589d
initial working implementation of standalone markdown plugin
thescientist13 Mar 15, 2025
8c733ad
move ToC heading loading to markdown plugin
thescientist13 Mar 17, 2025
fbed9aa
minimal interop with graphql plugin
thescientist13 Mar 20, 2025
2c1b049
adopt correct repository field convention in package.json
thescientist13 Apr 27, 2025
977c3f8
migrate standard markdown plugin test case to markdown plugin package
thescientist13 Apr 27, 2025
9d7ef96
use String constructor
thescientist13 Apr 27, 2025
d7c0107
move markdown plugins test case to markdown package
thescientist13 Apr 27, 2025
510a3db
migrate WCC prerendering in markdown test case to markdown plugin
thescientist13 Apr 27, 2025
850588e
migrate markdown 404 page test case to markdown plugin
thescientist13 Apr 27, 2025
cf2d05d
misc rebase sync changes
thescientist13 Aug 16, 2025
e302b5e
refactoring markdown out of all CLI test cases
thescientist13 Aug 17, 2025
ee53b43
refine 404 handling
thescientist13 Aug 17, 2025
e12b8ca
add context plugin test cases to markdown plugin
thescientist13 Aug 17, 2025
b58f86f
refine production server response statusText
thescientist13 Aug 17, 2025
f170fd8
handle markdown and custom elements p tag wrapping
thescientist13 Aug 17, 2025
1b90ba0
enable test logging for failing test case
thescientist13 Aug 17, 2025
97a69b3
refactor preServe transforming in development server
thescientist13 Aug 19, 2025
0194073
clean up resource plugin filtering in serve lifecycle
thescientist13 Aug 19, 2025
c630ae6
one more attempt at dev server test case failures
thescientist13 Aug 19, 2025
dfb4b4b
refactor away from preServe lifecycle
thescientist13 Aug 26, 2025
1363f1e
cleanup
thescientist13 Aug 26, 2025
09f98c6
more preServe cleanup
thescientist13 Aug 26, 2025
62a0b2b
add clone
thescientist13 Aug 26, 2025
701216d
bump alpha version
thescientist13 Aug 26, 2025
005e40b
update lock file
thescientist13 Aug 26, 2025
ff3838c
rollback preServe related changes
thescientist13 Aug 26, 2025
23fefca
revert back to async reduce pattern in serve lifecycle for dev server…
thescientist13 Aug 30, 2025
a880798
restore commander
thescientist13 Aug 30, 2025
f2286b0
fix static router test cases
thescientist13 Aug 31, 2025
e6cb048
restore more test cases
thescientist13 Aug 31, 2025
4b61bc1
refactor servePage option for custom page formats
thescientist13 Aug 31, 2025
7d588e9
remove frontmatter dependency
thescientist13 Aug 31, 2025
3b25346
document markdown plugin options
thescientist13 Aug 31, 2025
89adcea
restore frontmatter plugin
thescientist13 Aug 31, 2025
63233e8
Revert "revert back to async reduce pattern in serve lifecycle for de…
KaiPrince Sep 1, 2025
7447a1d
clone everywhere
KaiPrince Sep 1, 2025
84385fb
debug
KaiPrince Sep 1, 2025
caa2043
debug
KaiPrince Sep 1, 2025
20abcc5
revert .only
KaiPrince Sep 1, 2025
ae87ea0
more debug
KaiPrince Sep 1, 2025
5aefc3e
fix debug
KaiPrince Sep 1, 2025
02ca213
add wasUsed debug
KaiPrince Sep 1, 2025
0a566b3
fix bodyUsed debug
KaiPrince Sep 1, 2025
227f129
debug wasUsed after
KaiPrince Sep 1, 2025
b1606b8
more debug
KaiPrince Sep 1, 2025
fd2a052
empty commit
KaiPrince Sep 1, 2025
0e714e4
Revert "more debug"
KaiPrince Sep 1, 2025
19d3dd1
Revert "clone everywhere"
KaiPrince Sep 1, 2025
a676b56
Reapply "more debug"
KaiPrince Sep 1, 2025
9dbb37d
try alternate fix
KaiPrince Sep 1, 2025
b188d32
Revert "try alternate fix"
KaiPrince Sep 2, 2025
60fe5cf
more debug
KaiPrince Sep 2, 2025
748b163
try another alternate fix
KaiPrince Sep 3, 2025
7634e35
empty commit
KaiPrince Sep 3, 2025
9434862
debug
KaiPrince Sep 3, 2025
7ac0328
more debug
KaiPrince Sep 3, 2025
df31b11
update alternate fix
KaiPrince Sep 3, 2025
f49bfe7
empty commit
KaiPrince Sep 3, 2025
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
7 changes: 4 additions & 3 deletions greenwood.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { greenwoodPluginPolyfills } from "@greenwood/plugin-polyfills";
import { greenwoodPluginPostCss } from "@greenwood/plugin-postcss";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { greenwoodPluginRendererPuppeteer } from "@greenwood/plugin-renderer-puppeteer";
import { greenwoodPluginMarkdown } from "@greenwood/plugin-markdown";
import rollupPluginAnalyzer from "rollup-plugin-analyzer";

/** @type {import('@greenwood/cli').Config} */
Expand All @@ -14,6 +15,9 @@ export default {
activeContent: true,
prerender: true,
plugins: [
greenwoodPluginMarkdown({
plugins: ["@mapbox/rehype-prism", "rehype-slug", "rehype-autolink-headings", "remark-github"],
}),
greenwoodPluginGraphQL(),
greenwoodPluginPolyfills({
lit: true,
Expand All @@ -39,7 +43,4 @@ export default {
},
},
],
markdown: {
plugins: ["@mapbox/rehype-prism", "rehype-slug", "rehype-autolink-headings", "remark-github"],
},
};
19 changes: 10 additions & 9 deletions greenwood.config.test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { greenwoodPluginImportCommonJs } from "@greenwood/plugin-import-commonjs
import { greenwoodPluginImportJsx } from "@greenwood/plugin-import-jsx";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { greenwoodPluginIncludeHTML } from "@greenwood/plugin-include-html";
import { greenwoodPluginMarkdown } from "@greenwood/plugin-markdown";
import { greenwoodPluginPolyfills } from "@greenwood/plugin-polyfills";
import { greenwoodPluginPostCss } from "@greenwood/plugin-postcss";
import { greenwoodPluginRendererLit } from "@greenwood/plugin-renderer-lit";
Expand Down Expand Up @@ -46,15 +47,6 @@ const config: Config = {
isolation: true,
layoutsDirectory: "/my-layouts",
optimization: "default",
markdown: {
plugins: [
"@mapbox/rehype-prism",
{
name: "rehype-autolink-headings",
options: { behavior: "append" },
},
],
},
pagesDirectory: "/my-pages",
plugins: [
greenwoodPluginAdapterAws(),
Expand All @@ -68,6 +60,15 @@ const config: Config = {
greenwoodPluginImportJsx(),
greenwoodPluginImportRaw,
greenwoodPluginIncludeHTML(),
greenwoodPluginMarkdown({
plugins: [
"@mapbox/rehype-prism",
{
name: "rehype-autolink-headings",
options: { behavior: "append" },
},
],
}),
greenwoodPluginPolyfills(),
greenwoodPluginPostCss(),
greenwoodPluginRendererLit(),
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,13 @@
"koa": "^3.0.1",
"koa-body": "^6.0.1",
"livereload": "^0.9.1",
"markdown-toc": "^1.2.0",
"node-html-parser": "^7.0.1",
"rehype-raw": "^7.0.0",
"rehype-stringify": "^10.0.1",
"remark-frontmatter": "^5.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.1",
"rollup": "^4.26.0",
"unified": "^11.0.5",
"wc-compiler": "~0.17.0"
},
"devDependencies": {
"@aws-sdk/client-cloudfront": "^3.726.0",
"@beforesemicolon/markup": "^1.14.1",
"@mapbox/rehype-prism": "^0.5.0",
"@shoelace-style/shoelace": "^2.18.0",
"@spectrum-css/card": "^9.3.0",
"@spectrum-web-components/action-menu": "^1.0.1",
Expand All @@ -92,8 +84,6 @@
"pwa-helpers": "^0.9.1",
"redux": "^5.0.1",
"redux-thunk": "^3.1.0",
"rehype-autolink-headings": "^4.0.0",
"rehype-slug": "^3.0.0",
"signal-utils": "^0.21.1",
"simpledotcss": "^1.0.0",
"tslib": "^2.8.1"
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/lib/layout-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ async function mergeContentIntoLayout(
: childRoot.querySelector("html") && childBody
? childBody
: !childRoot.querySelector("html")
? childContents
? childRoot.querySelector("body")
? childBody
: childContents
: "";

// we wrap SSR content in comments so we can extract it during prerendering to avoid double pre-rendering
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/lifecycles/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const defaultConfig = {
},
isolation: false,
layoutsDirectory: "layouts",
markdown: { plugins: [] },
optimization: optimizations[0],
pagesDirectory: "pages",
plugins: greenwoodPlugins,
Expand Down
51 changes: 12 additions & 39 deletions packages/cli/src/lifecycles/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fs from "node:fs/promises";
import fm from "front-matter";
import { checkResourceExists, requestAsObject } from "../lib/resource-utils.js";
import { activeFrontmatterKeys } from "../lib/content-utils.js";
import toc from "markdown-toc";
import { Worker } from "node:worker_threads";

function getLabelFromRoute(_route) {
Expand All @@ -27,7 +26,7 @@ function getLabelFromRoute(_route) {
}

function getIdFromRelativePathPath(relativePathPath, extension) {
return relativePathPath.replace(extension, "").replace("./", "").replace(/\//g, "-");
return relativePathPath.replace(`.${extension}`, "").replace("./", "").replace(/\//g, "-");
}

function trackCollectionsForPage(page, collections) {
Expand Down Expand Up @@ -79,29 +78,26 @@ const generateGraph = async (compilation) => {
pages = nextPages.pages;
apiRoutes = nextPages.apiRoutes;
} else {
const extension = `.${filenameUrl.pathname.split(".").pop()}`;
const extension = `${filenameUrl.pathname.split(".").pop()}`;
const relativePagePath = filenameUrl.pathname.replace(pagesDir.pathname, "./");
const isApiRoute = relativePagePath.startsWith("./api");
const req = isApiRoute
? new Request(filenameUrl, { headers: { Accept: "text/javascript" } })
: new Request(filenameUrl, { headers: { Accept: "text/html" } });
let isCustom = null;

for (const plugin of customPageFormatPlugins) {
if (plugin.shouldServe && (await plugin.shouldServe(filenameUrl, req))) {
if (plugin.servePage && plugin.extensions.includes(extension)) {
isCustom = plugin.servePage;
break;
}
}

const isStatic = isCustom === "static" || extension === ".md" || extension === ".html";
const isDynamic = isCustom === "dynamic" || extension === ".js" || extension === ".ts";
const isStatic = isCustom === "static" || extension === "html";
const isDynamic = isCustom === "dynamic" || extension === "js" || extension === "ts";
const isPage = isStatic || isDynamic;
let route = `${relativePagePath.replace(".", "").replace(`${extension}`, "")}`;
let route = `${relativePagePath.replace(".", "").replace(`.${extension}`, "")}`;
let fileContents;

if (isApiRoute) {
if (extension !== ".js" && extension !== ".ts" && !isCustom) {
if (extension !== "js" && extension !== "ts" && !isCustom) {
console.warn(`${filenameUrl} is not a supported API file extension, skipping...`);
return;
}
Expand All @@ -123,12 +119,14 @@ const generateGraph = async (compilation) => {
getIdFromRelativePathPath(relativePagePath, extension).replace("api-", ""),
),
pageHref: new URL(relativePagePath, pagesDir).href,
outputHref: new URL(relativePagePath, outputDir).href.replace(extension, ".js"),
outputHref: new URL(relativePagePath, outputDir).href.replace(`.${extension}`, ".js"),
route: `${basePath}${route}`,
isolation,
});
} else if (isPage) {
let root = filename.split("/")[filename.split("/").length - 1].replace(extension, "");
let root = filename
.split("/")
[filename.split("/").length - 1].replace(`.${extension}`, "");
// should we even have a default page layout?
// https://github.com/ProjectEvergreen/greenwood/issues/1271
let layout = "page";
Expand Down Expand Up @@ -223,36 +221,11 @@ const generateGraph = async (compilation) => {
}
}

/*
* Custom front matter - Variable Definitions
* --------------------------------------------------
* collection: the name of the collection for the page (as a string or array)
* order: the order of this item within the collection
* tocHeading: heading size to use a Table of Contents for a page
* tableOfContents: json object containing page's table of contents (list of headings)
*/

// prune "reserved" attributes that are supported by Greenwood
// prune "reserved" frontmatter that are supported by Greenwood
[...activeFrontmatterKeys, "layout"].forEach((key) => {
delete customData[key];
});

// set flag whether to gather a list of headings on a page as menu items
customData.tocHeading = customData.tocHeading || 0;
customData.tableOfContents = [];

if (fileContents && customData.tocHeading > 0 && customData.tocHeading <= 6) {
// parse markdown for table of contents and output to json
customData.tableOfContents = toc(fileContents).json;

// parse table of contents for only the pages user wants linked
if (customData.tableOfContents.length > 0 && customData.tocHeading > 0) {
customData.tableOfContents = customData.tableOfContents.filter(
(item) => item.lvl === customData.tocHeading,
);
}
}

/*
* Page Properties
*----------------------
Expand Down
53 changes: 38 additions & 15 deletions packages/cli/src/lifecycles/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ async function getDevServer(compilation) {
const app = new Koa();
const compilationCopy = Object.assign({}, compilation);
const resourcePlugins = [
// Greenwood default standard resource and import plugins
...compilation.config.plugins
.filter((plugin) => {
return plugin.type === "resource" && plugin.isGreenwoodDefaultPlugin;
return plugin.type === "resource";
})
.map((plugin) => {
return plugin.provider(compilationCopy);
}),

// custom user resource plugins
...compilation.config.plugins
.filter((plugin) => {
return plugin.type === "resource" && !plugin.isGreenwoodDefaultPlugin;
})
.map((plugin) => plugin.provider(compilationCopy)),
];

app.use(koaBody());
Expand All @@ -57,7 +49,7 @@ async function getDevServer(compilation) {
await next();
});

// handle creating responses from urls
// handle serving responses from urls
app.use(async (ctx, next) => {
try {
const url = new URL(ctx.url);
Expand All @@ -66,15 +58,43 @@ async function getDevServer(compilation) {
// intentionally ignore initial statusText to avoid false positives from 404s
let response = new Response(null, { status });

const pluginNames = [];
const wasUsed = [];

for (const plugin of resourcePlugins) {
if (plugin.shouldServe && (await plugin.shouldServe(url, request))) {
const current = await plugin.serve(url, request);
const merged = mergeResponse(response.clone(), current.clone());
// ignore plugins that serve pages, as those will be handled by Greenwood's standard HTML plugin
if (
!plugin.servePage &&
plugin.shouldServe &&
(await plugin.shouldServe(url, request, response.clone()))
) {
pluginNames.push(plugin.constructor.name);
wasUsed.push(response.bodyUsed);
try {
const newLocal = response.clone();
wasUsed.push(response.bodyUsed);
const current = await plugin.serve(
url,
request,
["StandardAudioResource", "StandardJavaScriptResource"].includes(
plugin.constructor.name,
)
? newLocal
: response.clone(),
);
wasUsed.push(response.bodyUsed);
const merged = mergeResponse(response.clone(), current.clone());

response = merged.clone();
response = merged.clone();
} catch (err) {
console.log("Error!", pluginNames, wasUsed, err);
throw err;
}
}
}

console.log("No error!", pluginNames, wasUsed);

ctx.body = response.body ? Readable.from(response.body) : "";
ctx.status = response.status;
ctx.message = response.statusText;
Expand Down Expand Up @@ -177,7 +197,7 @@ async function getDevServer(compilation) {
statusText: message,
status,
headers: new Headers(header),
}).clone();
});
const splitResponse = response.clone();
const contents = await splitResponse.text();
const inm = ctx.headers["if-none-match"];
Expand Down Expand Up @@ -250,6 +270,7 @@ async function getStaticServer(compilation, composable) {
}
} else {
ctx.body = "Not Found";
ctx.message = "Not Found";
ctx.status = 404;
ctx.set("Content-Type", "text/plain");
}
Expand Down Expand Up @@ -323,6 +344,7 @@ async function getStaticServer(compilation, composable) {

ctx.body = body;
ctx.status = 200;
ctx.message = "OK";
ctx.set("Content-Type", "text/html");
}
} catch (e) {
Expand Down Expand Up @@ -392,6 +414,7 @@ async function getHybridServer(compilation) {
}

ctx.body = html;
ctx.message = "OK";
ctx.set("Content-Type", "text/html");
ctx.status = 200;
} else if (isApiRoute) {
Expand Down
Loading
Loading