basecampjs 0.0.4 → 0.0.6

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 +22 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -128,18 +128,20 @@ async function walkFiles(dir) {
128
128
  return results;
129
129
  }
130
130
 
131
- function createNunjucksEnv(layoutsDir, pagesDir, srcDir) {
132
- // Allow templates to resolve from layouts, pages, or the src root
131
+ function createNunjucksEnv(layoutsDir, pagesDir, srcDir, partialsDir) {
132
+ // Allow templates to resolve from layouts, partials, pages, or the src root
133
+ const searchPaths = [layoutsDir, partialsDir, pagesDir, srcDir].filter(Boolean);
133
134
  return new nunjucks.Environment(
134
- new nunjucks.FileSystemLoader([layoutsDir, pagesDir, srcDir], { noCache: true }),
135
+ new nunjucks.FileSystemLoader(searchPaths, { noCache: true }),
135
136
  { autoescape: false }
136
137
  );
137
138
  }
138
139
 
139
- function createLiquidEnv(layoutsDir, pagesDir, srcDir) {
140
+ function createLiquidEnv(layoutsDir, pagesDir, srcDir, partialsDir) {
140
141
  // Liquid loader will search these roots for partials/layouts
142
+ const root = [layoutsDir, partialsDir, pagesDir, srcDir].filter(Boolean);
141
143
  return new Liquid({
142
- root: [layoutsDir, pagesDir, srcDir],
144
+ root,
143
145
  extname: ".liquid",
144
146
  cache: false
145
147
  });
@@ -147,18 +149,24 @@ function createLiquidEnv(layoutsDir, pagesDir, srcDir) {
147
149
 
148
150
  function toUrlPath(outRel) {
149
151
  const normalized = outRel.replace(/\\/g, "/");
150
- if (normalized.endsWith("index.html")) {
151
- const trimmed = normalized.slice(0, -"index.html".length);
152
- return trimmed ? `/${trimmed}` : "/";
152
+ let path = `/${normalized}`;
153
+ // Remove trailing index.html for directory-style URLs
154
+ if (path.endsWith("index.html")) {
155
+ path = path.slice(0, -"index.html".length);
153
156
  }
154
- return `/${normalized}`;
157
+ // Strip trailing slash except for root
158
+ if (path !== "/" && path.endsWith("/")) {
159
+ path = path.slice(0, -1);
160
+ }
161
+ return path || "/";
155
162
  }
156
163
 
157
164
  function pageContext(frontmatter, html, config, relPath, data, path = "/") {
158
165
  return {
159
166
  site: { name: config.siteName, config },
160
167
  page: { ...frontmatter, content: html, source: relPath, path },
161
- collections: data
168
+ collections: data,
169
+ ...data
162
170
  };
163
171
  }
164
172
 
@@ -255,11 +263,12 @@ async function build(cwdArg = cwd) {
255
263
  const srcDir = resolve(cwdArg, config.srcDir || "src");
256
264
  const pagesDir = join(srcDir, "pages");
257
265
  const layoutsDir = join(srcDir, "layouts");
266
+ const partialsDir = join(srcDir, "partials");
258
267
  const dataDir = join(srcDir, "data");
259
268
  const publicDir = resolve(cwdArg, "public");
260
269
  const outDir = resolve(cwdArg, config.outDir || "dist");
261
- const env = createNunjucksEnv(layoutsDir, pagesDir, srcDir);
262
- const liquidEnv = createLiquidEnv(layoutsDir, pagesDir, srcDir);
270
+ const env = createNunjucksEnv(layoutsDir, pagesDir, srcDir, partialsDir);
271
+ const liquidEnv = createLiquidEnv(layoutsDir, pagesDir, srcDir, partialsDir);
263
272
  const data = await loadData(dataDir);
264
273
 
265
274
  await cleanDir(outDir);
@@ -412,4 +421,4 @@ async function main() {
412
421
  main().catch((err) => {
413
422
  console.error(err);
414
423
  exit(1);
415
- });
424
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basecampjs",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "description": "BasecampJS engine for CampsiteJS static site generator.",
6
6
  "bin": {