basecampjs 0.0.3 → 0.0.5

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.
Files changed (2) hide show
  1. package/index.js +19 -16
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -147,20 +147,22 @@ function createLiquidEnv(layoutsDir, pagesDir, srcDir) {
147
147
 
148
148
  function toUrlPath(outRel) {
149
149
  const normalized = outRel.replace(/\\/g, "/");
150
- if (normalized.endsWith("index.html")) {
151
- const trimmed = normalized.slice(0, -"index.html".length);
152
- return trimmed ? `/${trimmed}` : "/";
150
+ let path = `/${normalized}`;
151
+ // Remove trailing index.html for directory-style URLs
152
+ if (path.endsWith("index.html")) {
153
+ path = path.slice(0, -"index.html".length);
153
154
  }
154
- return `/${normalized}`;
155
+ // Strip trailing slash except for root
156
+ if (path !== "/" && path.endsWith("/")) {
157
+ path = path.slice(0, -1);
158
+ }
159
+ return path || "/";
155
160
  }
156
161
 
157
- function pageContext(frontmatter, html, config, relPath, data, url = "/") {
162
+ function pageContext(frontmatter, html, config, relPath, data, path = "/") {
158
163
  return {
159
164
  site: { name: config.siteName, config },
160
- page: { ...frontmatter, content: html, source: relPath, url },
161
- frontmatter,
162
- content: html,
163
- data,
165
+ page: { ...frontmatter, content: html, source: relPath, path },
164
166
  collections: data,
165
167
  ...data
166
168
  };
@@ -176,8 +178,9 @@ async function renderWithLayout(layoutName, html, ctx, env, liquidEnv) {
176
178
  const ext = extname(layoutName).toLowerCase();
177
179
  const layoutCtx = {
178
180
  ...ctx,
181
+ frontmatter: ctx.page || {},
179
182
  content: html,
180
- title: ctx.frontmatter?.title ?? ctx.page?.title ?? ctx.site?.name
183
+ title: ctx.page?.title ?? ctx.site?.name
181
184
  };
182
185
 
183
186
  if (ext === ".njk") {
@@ -197,14 +200,14 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
197
200
  const ext = extname(filePath).toLowerCase();
198
201
  const outRel = rel.replace(/\.liquid(\.html)?$/i, ".html").replace(ext, ".html");
199
202
  const outPath = join(outDir, outRel);
200
- const url = toUrlPath(outRel);
203
+ const path = toUrlPath(outRel);
201
204
  await ensureDir(dirname(outPath));
202
205
 
203
206
  if (ext === ".md") {
204
207
  const raw = await readFile(filePath, "utf8");
205
208
  const parsed = matter(raw);
206
209
  const html = md.render(parsed.content);
207
- const ctx = pageContext(parsed.data, html, config, rel, data, url);
210
+ const ctx = pageContext(parsed.data, html, config, rel, data, path);
208
211
  const rendered = await renderWithLayout(parsed.data.layout, html, ctx, env, liquidEnv);
209
212
  await writeFile(outPath, rendered, "utf8");
210
213
  return;
@@ -213,7 +216,7 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
213
216
  if (ext === ".njk") {
214
217
  const raw = await readFile(filePath, "utf8");
215
218
  const parsed = matter(raw);
216
- const ctx = pageContext(parsed.data, parsed.content, config, rel, data, url);
219
+ const ctx = pageContext(parsed.data, parsed.content, config, rel, data, path);
217
220
  const templateName = rel.replace(/\\/g, "/");
218
221
  let pageHtml = env.renderString(parsed.content, ctx, { path: templateName });
219
222
  if (shouldRenderMarkdown(parsed.data, config, false)) {
@@ -227,7 +230,7 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
227
230
  if (ext === ".liquid" || filePath.toLowerCase().endsWith(".liquid.html")) {
228
231
  const raw = await readFile(filePath, "utf8");
229
232
  const parsed = matter(raw);
230
- const ctx = pageContext(parsed.data, parsed.content, config, rel, data, url);
233
+ const ctx = pageContext(parsed.data, parsed.content, config, rel, data, path);
231
234
  let pageHtml = await liquidEnv.parseAndRender(parsed.content, ctx);
232
235
  if (shouldRenderMarkdown(parsed.data, config, false)) {
233
236
  pageHtml = md.render(pageHtml);
@@ -240,7 +243,7 @@ async function renderPage(filePath, { pagesDir, layoutsDir, outDir, env, liquidE
240
243
  if (ext === ".html") {
241
244
  const raw = await readFile(filePath, "utf8");
242
245
  const parsed = matter(raw);
243
- const ctx = pageContext(parsed.data, parsed.content, config, rel, data, url);
246
+ const ctx = pageContext(parsed.data, parsed.content, config, rel, data, path);
244
247
  let pageHtml = parsed.content;
245
248
  if (shouldRenderMarkdown(parsed.data, config, false)) {
246
249
  pageHtml = md.render(pageHtml);
@@ -415,4 +418,4 @@ async function main() {
415
418
  main().catch((err) => {
416
419
  console.error(err);
417
420
  exit(1);
418
- });
421
+ });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "basecampjs",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
- "description": "BasecampJS engine for Campsite static site generator.",
5
+ "description": "BasecampJS engine for CampsiteJS static site generator.",
6
6
  "bin": {
7
7
  "campsite": "./index.js"
8
8
  },