basecampjs 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +10 -13
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -154,15 +154,11 @@ function toUrlPath(outRel) {
|
|
|
154
154
|
return `/${normalized}`;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
function pageContext(frontmatter, html, config, relPath, data,
|
|
157
|
+
function pageContext(frontmatter, html, config, relPath, data, path = "/") {
|
|
158
158
|
return {
|
|
159
159
|
site: { name: config.siteName, config },
|
|
160
|
-
page: { ...frontmatter, content: html, source: relPath,
|
|
161
|
-
|
|
162
|
-
content: html,
|
|
163
|
-
data,
|
|
164
|
-
collections: data,
|
|
165
|
-
...data
|
|
160
|
+
page: { ...frontmatter, content: html, source: relPath, path },
|
|
161
|
+
collections: data
|
|
166
162
|
};
|
|
167
163
|
}
|
|
168
164
|
|
|
@@ -176,8 +172,9 @@ async function renderWithLayout(layoutName, html, ctx, env, liquidEnv) {
|
|
|
176
172
|
const ext = extname(layoutName).toLowerCase();
|
|
177
173
|
const layoutCtx = {
|
|
178
174
|
...ctx,
|
|
175
|
+
frontmatter: ctx.page || {},
|
|
179
176
|
content: html,
|
|
180
|
-
title: ctx.
|
|
177
|
+
title: ctx.page?.title ?? ctx.site?.name
|
|
181
178
|
};
|
|
182
179
|
|
|
183
180
|
if (ext === ".njk") {
|
|
@@ -197,14 +194,14 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
|
|
|
197
194
|
const ext = extname(filePath).toLowerCase();
|
|
198
195
|
const outRel = rel.replace(/\.liquid(\.html)?$/i, ".html").replace(ext, ".html");
|
|
199
196
|
const outPath = join(outDir, outRel);
|
|
200
|
-
const
|
|
197
|
+
const path = toUrlPath(outRel);
|
|
201
198
|
await ensureDir(dirname(outPath));
|
|
202
199
|
|
|
203
200
|
if (ext === ".md") {
|
|
204
201
|
const raw = await readFile(filePath, "utf8");
|
|
205
202
|
const parsed = matter(raw);
|
|
206
203
|
const html = md.render(parsed.content);
|
|
207
|
-
const ctx = pageContext(parsed.data, html, config, rel, data,
|
|
204
|
+
const ctx = pageContext(parsed.data, html, config, rel, data, path);
|
|
208
205
|
const rendered = await renderWithLayout(parsed.data.layout, html, ctx, env, liquidEnv);
|
|
209
206
|
await writeFile(outPath, rendered, "utf8");
|
|
210
207
|
return;
|
|
@@ -213,7 +210,7 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
|
|
|
213
210
|
if (ext === ".njk") {
|
|
214
211
|
const raw = await readFile(filePath, "utf8");
|
|
215
212
|
const parsed = matter(raw);
|
|
216
|
-
const ctx = pageContext(parsed.data, parsed.content, config, rel, data,
|
|
213
|
+
const ctx = pageContext(parsed.data, parsed.content, config, rel, data, path);
|
|
217
214
|
const templateName = rel.replace(/\\/g, "/");
|
|
218
215
|
let pageHtml = env.renderString(parsed.content, ctx, { path: templateName });
|
|
219
216
|
if (shouldRenderMarkdown(parsed.data, config, false)) {
|
|
@@ -227,7 +224,7 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
|
|
|
227
224
|
if (ext === ".liquid" || filePath.toLowerCase().endsWith(".liquid.html")) {
|
|
228
225
|
const raw = await readFile(filePath, "utf8");
|
|
229
226
|
const parsed = matter(raw);
|
|
230
|
-
const ctx = pageContext(parsed.data, parsed.content, config, rel, data,
|
|
227
|
+
const ctx = pageContext(parsed.data, parsed.content, config, rel, data, path);
|
|
231
228
|
let pageHtml = await liquidEnv.parseAndRender(parsed.content, ctx);
|
|
232
229
|
if (shouldRenderMarkdown(parsed.data, config, false)) {
|
|
233
230
|
pageHtml = md.render(pageHtml);
|
|
@@ -240,7 +237,7 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
|
|
|
240
237
|
if (ext === ".html") {
|
|
241
238
|
const raw = await readFile(filePath, "utf8");
|
|
242
239
|
const parsed = matter(raw);
|
|
243
|
-
const ctx = pageContext(parsed.data, parsed.content, config, rel, data,
|
|
240
|
+
const ctx = pageContext(parsed.data, parsed.content, config, rel, data, path);
|
|
244
241
|
let pageHtml = parsed.content;
|
|
245
242
|
if (shouldRenderMarkdown(parsed.data, config, false)) {
|
|
246
243
|
pageHtml = md.render(pageHtml);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basecampjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "BasecampJS engine for
|
|
5
|
+
"description": "BasecampJS engine for CampsiteJS static site generator.",
|
|
6
6
|
"bin": {
|
|
7
7
|
"campsite": "./index.js"
|
|
8
8
|
},
|