mirror of
https://github.com/benjaminion/upgrading-ethereum-book.git
synced 2026-01-09 14:38:08 -05:00
Avoid the need to patch astro
This commit is contained in:
@@ -99,7 +99,6 @@ There are various npm script commands to help with building and testing. See `pa
|
||||
- `npm run stats` shows some stats about the book. Build the PDF first to get the full set.
|
||||
- `npm run debug` builds with debugging output for my custom integrations.
|
||||
- `npm run minim` does a minimal build with only a couple of pages. See `src/content.config.js`.
|
||||
- `npm run patch` applies my patches to the Astro NPM package using [`custompatch`](https://www.npmjs.com/package/custompatch).
|
||||
|
||||
### Environment variables
|
||||
|
||||
|
||||
1523
package-lock.json
generated
1523
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,6 @@
|
||||
"author": "Ben Edgington",
|
||||
"keywords": [],
|
||||
"scripts": {
|
||||
"prepare": "custompatch",
|
||||
"devel": "astro dev",
|
||||
"build": "astro build",
|
||||
"minim": "rm -rf dist/ node_modules/.astro && UE_MINIMAL=t astro build",
|
||||
@@ -22,12 +21,10 @@
|
||||
"gramm": "bin/util/check_grammar.sh src/book.md",
|
||||
"pdfit": "bin/pdf/make_pdf src/book.md",
|
||||
"stats": "bin/util/stats.sh",
|
||||
"valid": "node --input-type=module -e 'import validateHtml from \"./bin/util/validate.js\"; validateHtml(\"dist/part2/building_blocks/ssz/index.html\")'",
|
||||
"patch": "custompatch"
|
||||
"valid": "node --input-type=module -e 'import validateHtml from \"./bin/util/validate.js\"; validateHtml(\"dist/part2/building_blocks/ssz/index.html\")'"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^5.9.2",
|
||||
"custompatch": "^1.1.7",
|
||||
"glob": "^11.0.2",
|
||||
"hast-util-select": "^6.0.4",
|
||||
"hast-util-to-string": "^3.0.1",
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
Index: /astro/dist/content/content-layer.js
|
||||
===================================================================
|
||||
--- /astro/dist/content/content-layer.js
|
||||
+++ /astro/dist/content/content-layer.js
|
||||
@@ -96,11 +96,11 @@
|
||||
...this.#settings.dataEntryTypes
|
||||
])
|
||||
};
|
||||
}
|
||||
- async #processMarkdown(content) {
|
||||
+ async #processMarkdown(content, opts) {
|
||||
this.#markdownProcessor ??= await createMarkdownProcessor(this.#settings.config.markdown);
|
||||
- const { code, metadata } = await this.#markdownProcessor.render(content);
|
||||
+ const { code, metadata } = await this.#markdownProcessor.render(content, opts);
|
||||
return {
|
||||
html: code,
|
||||
metadata
|
||||
};
|
||||
@@ -7,12 +7,6 @@ import { fileURLToPath } from 'node:url';
|
||||
const regex =
|
||||
/^(?<level>#{1,3}) (?<title>.+) <!-- (?<path>\/.*\/)(?<hide>\*?) -->$/gm;
|
||||
|
||||
// Note that this relies on modifying the astro package to add an `opts` argument
|
||||
// to `.render` (see ../patches) in order to get the frontmatter correctly propagated.
|
||||
//
|
||||
// I can't find an "official" way to do this. Prepending synthetic frontmatter before
|
||||
// doing renderMarkdown does not work.
|
||||
|
||||
function delay(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
@@ -38,7 +32,7 @@ async function syncBook(
|
||||
fileName,
|
||||
store,
|
||||
parseData,
|
||||
renderMarkdown,
|
||||
render,
|
||||
generateDigest,
|
||||
logger,
|
||||
isWatcherUpdate,
|
||||
@@ -139,12 +133,13 @@ async function syncBook(
|
||||
data: frontmatter,
|
||||
});
|
||||
|
||||
// Use the hacked version - I'd love to avoid this!
|
||||
const rendered = await renderMarkdown(markdown, {
|
||||
frontmatter: frontmatter,
|
||||
fileURL: m.groups.path,
|
||||
const rendered = await render({
|
||||
id: m.groups.path,
|
||||
data: frontmatter,
|
||||
body: markdown,
|
||||
filePath: m.groups.path,
|
||||
digest: digest,
|
||||
});
|
||||
// const rendered = await renderMarkdown(markdown);
|
||||
|
||||
store.set({
|
||||
id: m.groups.path,
|
||||
@@ -169,21 +164,23 @@ export function bookLoader(fileName) {
|
||||
collection,
|
||||
store,
|
||||
parseData,
|
||||
renderMarkdown,
|
||||
generateDigest,
|
||||
config,
|
||||
watcher,
|
||||
logger,
|
||||
entryTypes,
|
||||
}) => {
|
||||
const filePath = fileURLToPath(new URL(fileName, config.root));
|
||||
logger.debug(`FilePath: ${filePath}`);
|
||||
|
||||
const render = await entryTypes.get('.md').getRenderFunction(config);
|
||||
|
||||
logger.info(`Reading ${collection} from ${fileName}`);
|
||||
await syncBook(
|
||||
fileName,
|
||||
store,
|
||||
parseData,
|
||||
renderMarkdown,
|
||||
render,
|
||||
generateDigest,
|
||||
logger,
|
||||
false,
|
||||
@@ -196,7 +193,7 @@ export function bookLoader(fileName) {
|
||||
fileName,
|
||||
store,
|
||||
parseData,
|
||||
renderMarkdown,
|
||||
render,
|
||||
generateDigest,
|
||||
logger,
|
||||
true,
|
||||
|
||||
@@ -10,9 +10,6 @@ const preamble =
|
||||
'**Note:** This page is automatically generated from the chapters ' +
|
||||
'in [Part 3](/part3/). You may find that some internal links are broken.';
|
||||
|
||||
// Note that this relies on modifying the astro package to add an `opts` argument
|
||||
// to `.render` (see ../patches) in order to get the frontmatter correctly propagated.
|
||||
|
||||
export function specLoader(fileName) {
|
||||
return {
|
||||
name: 'spec-loader',
|
||||
@@ -20,9 +17,10 @@ export function specLoader(fileName) {
|
||||
collection,
|
||||
store,
|
||||
parseData,
|
||||
renderMarkdown,
|
||||
generateDigest,
|
||||
config,
|
||||
logger,
|
||||
entryTypes,
|
||||
}) => {
|
||||
logger.info(`Reading ${collection} from ${fileName}`);
|
||||
|
||||
@@ -74,12 +72,14 @@ export function specLoader(fileName) {
|
||||
data: frontmatter,
|
||||
});
|
||||
|
||||
// Use the hacked version - I'd love to avoid this!
|
||||
const rendered = await renderMarkdown(markdown, {
|
||||
frontmatter: frontmatter,
|
||||
fileURL: path,
|
||||
const render = await entryTypes.get('.md').getRenderFunction(config);
|
||||
const rendered = await render({
|
||||
id: path,
|
||||
data: frontmatter,
|
||||
body: markdown,
|
||||
filePath: path,
|
||||
digest: digest,
|
||||
});
|
||||
// const rendered = await renderMarkdown(markdown);
|
||||
|
||||
store.set({
|
||||
id: path,
|
||||
|
||||
Reference in New Issue
Block a user