@rettangoli/sites 0.2.1 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/sites",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Generate static sites using Markdown and YAML. Straightforward, zero-complexity. Complete toolkit for landing pages, blogs, documentation, admin dashboards, and more.git remote add origin git@github.com:yuusoft-org/sitic.git",
5
5
  "author": {
6
6
  "name": "Luciano Hanyon Wu",
package/src/cli/build.js CHANGED
@@ -8,9 +8,10 @@ import { loadSiteConfig } from '../utils/loadSiteConfig.js';
8
8
  * @param {string} options.rootDir - Root directory of the site (defaults to cwd)
9
9
  * @param {Object} options.md - Optional markdown renderer
10
10
  * @param {boolean} options.quiet - Suppress build output logs
11
+ * @param {boolean} options.isScreenshotMode - Whether building for screenshot capture
11
12
  */
12
13
  export const buildSite = async (options = {}) => {
13
- const { rootDir = process.cwd(), md, functions, quiet = false } = options;
14
+ const { rootDir = process.cwd(), md, functions, quiet = false, isScreenshotMode = false } = options;
14
15
 
15
16
  // Load config file if needed
16
17
  let config = {};
@@ -23,7 +24,8 @@ export const buildSite = async (options = {}) => {
23
24
  rootDir,
24
25
  md: md || config.mdRender,
25
26
  functions: functions || config.functions || {},
26
- quiet
27
+ quiet,
28
+ isScreenshotMode
27
29
  });
28
30
 
29
31
  await build();
@@ -31,7 +31,7 @@ function isObject(item) {
31
31
  return item && typeof item === 'object' && !Array.isArray(item);
32
32
  }
33
33
 
34
- export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet = false }) {
34
+ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet = false, isScreenshotMode = false }) {
35
35
  return async function build() {
36
36
  // Use provided md or default to rtglMarkdown
37
37
  const mdInstance = md || rtglMarkdown(MarkdownIt);
@@ -148,15 +148,18 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
148
148
  const frontmatter = extractFrontmatter(itemPath);
149
149
 
150
150
  // Calculate URL
151
- const outputFileName = item.name.replace(/\.(yaml|md)$/, '.html');
152
- const outputRelativePath = basePath ? path.join(basePath, outputFileName) : outputFileName;
153
- let url = '/' + outputRelativePath.replace(/\\/g, '/').replace(/\.html$/, '');
154
- // Special case: /index becomes /
155
- if (url === '/index') {
156
- url = '/';
151
+ const baseFileName = item.name.replace(/\.(yaml|md)$/, '');
152
+ let url;
153
+
154
+ // Special case: index files remain at root, others become directories
155
+ if (baseFileName === 'index') {
156
+ url = basePath ? '/' + basePath.replace(/\\/g, '/') : '/';
157
+ if (url !== '/') {
158
+ url = url + '/';
159
+ }
157
160
  } else {
158
- // Add trailing slash for all non-root URLs
159
- url = url + '/';
161
+ const pagePath = basePath ? path.join(basePath, baseFileName) : baseFileName;
162
+ url = '/' + pagePath.replace(/\\/g, '/') + '/';
160
163
  }
161
164
 
162
165
  // Process tags
@@ -227,19 +230,26 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
227
230
  const rawContent = lines.slice(contentStart).join('\n').trim();
228
231
 
229
232
  // Calculate URL for current page
230
- let url = '/' + outputRelativePath.replace(/\\/g, '/').replace(/\.html$/, '');
231
- // Special case: /index becomes /
232
- if (url === '/index') {
233
- url = '/';
233
+ let url;
234
+ const fileName = path.basename(outputRelativePath, '.html');
235
+ const basePath = path.dirname(outputRelativePath);
236
+
237
+ // Special case: index files remain at root, others become directories
238
+ if (fileName === 'index') {
239
+ url = basePath && basePath !== '.' ? '/' + basePath.replace(/\\/g, '/') : '/';
240
+ if (url !== '/') {
241
+ url = url + '/';
242
+ }
234
243
  } else {
235
- // Add trailing slash for all non-root URLs
236
- url = url + '/';
244
+ const pagePath = basePath && basePath !== '.' ? path.join(basePath, fileName) : fileName;
245
+ url = '/' + pagePath.replace(/\\/g, '/') + '/';
237
246
  }
238
247
 
239
248
  // Deep merge global data with frontmatter and collections for the page context
240
249
  const pageData = deepMerge(globalData, frontmatter);
241
250
  pageData.collections = collections;
242
251
  pageData.page = { url };
252
+ pageData.build = { isScreenshotMode };
243
253
 
244
254
  let processedPageContent;
245
255
 
@@ -298,9 +308,36 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
298
308
  htmlString = convertToHtml(resultArray);
299
309
  }
300
310
 
301
- // Create output directory if it doesn't exist
302
- const outputPath = path.join(rootDir, '_site', outputRelativePath);
303
- const outputDir = path.dirname(outputPath);
311
+ // Create output directory and file path for new index.html structure
312
+ const pageFileName = path.basename(outputRelativePath, '.html');
313
+ const dirPath = path.dirname(outputRelativePath);
314
+
315
+ let outputPath, outputDir;
316
+
317
+ // Special case: index files remain as index.html, others become directory/index.html
318
+ if (pageFileName === 'index') {
319
+ if (dirPath && dirPath !== '.') {
320
+ // Nested index file: pages/blog/index.yaml -> _site/blog/index.html
321
+ outputPath = path.join(rootDir, '_site', dirPath, 'index.html');
322
+ outputDir = path.join(rootDir, '_site', dirPath);
323
+ } else {
324
+ // Root index file: pages/index.yaml -> _site/index.html
325
+ outputPath = path.join(rootDir, '_site', 'index.html');
326
+ outputDir = path.join(rootDir, '_site');
327
+ }
328
+ } else {
329
+ // Regular file: pages/test.yaml -> _site/test/index.html
330
+ if (dirPath && dirPath !== '.') {
331
+ // Nested regular file: pages/blog/post.yaml -> _site/blog/post/index.html
332
+ outputPath = path.join(rootDir, '_site', dirPath, pageFileName, 'index.html');
333
+ outputDir = path.join(rootDir, '_site', dirPath, pageFileName);
334
+ } else {
335
+ // Root level regular file: pages/test.yaml -> _site/test/index.html
336
+ outputPath = path.join(rootDir, '_site', pageFileName, 'index.html');
337
+ outputDir = path.join(rootDir, '_site', pageFileName);
338
+ }
339
+ }
340
+
304
341
  if (!fs.existsSync(outputDir)) {
305
342
  fs.mkdirSync(outputDir, { recursive: true });
306
343
  }
@@ -141,9 +141,9 @@ const screenshotCommand = async (options = {}) => {
141
141
  console.log('📋 Ignore patterns:', ignorePatterns);
142
142
  }
143
143
 
144
- // Build the site first
144
+ // Build the site first (with screenshot mode enabled)
145
145
  console.log('Building site...');
146
- await buildSite({ rootDir });
146
+ await buildSite({ rootDir, isScreenshotMode: true });
147
147
  console.log('Build complete');
148
148
 
149
149
  // Start temporary server