@rettangoli/sites 0.2.0-rc7 → 0.2.2
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 +3 -2
- package/src/cli/build.js +2 -2
- package/src/createSiteBuilder.js +67 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rettangoli/sites",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"memfs": "^4.36.0",
|
|
31
|
-
"puty": "^0.0.4"
|
|
31
|
+
"puty": "^0.0.4",
|
|
32
|
+
"vitest": "^3.2.4"
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"test": "vitest run --reporter=verbose"
|
package/src/cli/build.js
CHANGED
|
@@ -21,10 +21,10 @@ export const buildSite = async (options = {}) => {
|
|
|
21
21
|
const build = createSiteBuilder({
|
|
22
22
|
fs,
|
|
23
23
|
rootDir,
|
|
24
|
-
md: md || config.
|
|
24
|
+
md: md || config.mdRender,
|
|
25
25
|
functions: functions || config.functions || {},
|
|
26
26
|
quiet
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
build();
|
|
29
|
+
await build();
|
|
30
30
|
};
|
package/src/createSiteBuilder.js
CHANGED
|
@@ -32,7 +32,7 @@ function isObject(item) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet = false }) {
|
|
35
|
-
return function build() {
|
|
35
|
+
return async function build() {
|
|
36
36
|
// Use provided md or default to rtglMarkdown
|
|
37
37
|
const mdInstance = md || rtglMarkdown(MarkdownIt);
|
|
38
38
|
|
|
@@ -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
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Special case:
|
|
155
|
-
if (
|
|
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
|
-
|
|
159
|
-
url =
|
|
161
|
+
const pagePath = basePath ? path.join(basePath, baseFileName) : baseFileName;
|
|
162
|
+
url = '/' + pagePath.replace(/\\/g, '/') + '/';
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
// Process tags
|
|
@@ -191,7 +194,7 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
191
194
|
const collections = buildCollections();
|
|
192
195
|
|
|
193
196
|
// Function to process a single page file
|
|
194
|
-
function processPage(pagePath, outputRelativePath, isMarkdown = false) {
|
|
197
|
+
async function processPage(pagePath, outputRelativePath, isMarkdown = false) {
|
|
195
198
|
if (!quiet) console.log(`Processing ${pagePath}...`);
|
|
196
199
|
|
|
197
200
|
// Read page content
|
|
@@ -227,13 +230,19 @@ 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
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
236
|
-
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
|
|
@@ -245,7 +254,13 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
245
254
|
|
|
246
255
|
if (isMarkdown) {
|
|
247
256
|
// Process markdown content with MarkdownIt
|
|
248
|
-
|
|
257
|
+
//If markdownit async then use the async render method
|
|
258
|
+
let htmlContent;
|
|
259
|
+
if(mdInstance.renderAsync){
|
|
260
|
+
htmlContent = await mdInstance.renderAsync(rawContent);
|
|
261
|
+
} else {
|
|
262
|
+
htmlContent = mdInstance.render(rawContent);
|
|
263
|
+
}
|
|
249
264
|
// For markdown, store as raw HTML that will be inserted directly
|
|
250
265
|
processedPageContent = { __html: htmlContent };
|
|
251
266
|
} else {
|
|
@@ -292,9 +307,36 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
292
307
|
htmlString = convertToHtml(resultArray);
|
|
293
308
|
}
|
|
294
309
|
|
|
295
|
-
// Create output directory
|
|
296
|
-
const
|
|
297
|
-
const
|
|
310
|
+
// Create output directory and file path for new index.html structure
|
|
311
|
+
const pageFileName = path.basename(outputRelativePath, '.html');
|
|
312
|
+
const dirPath = path.dirname(outputRelativePath);
|
|
313
|
+
|
|
314
|
+
let outputPath, outputDir;
|
|
315
|
+
|
|
316
|
+
// Special case: index files remain as index.html, others become directory/index.html
|
|
317
|
+
if (pageFileName === 'index') {
|
|
318
|
+
if (dirPath && dirPath !== '.') {
|
|
319
|
+
// Nested index file: pages/blog/index.yaml -> _site/blog/index.html
|
|
320
|
+
outputPath = path.join(rootDir, '_site', dirPath, 'index.html');
|
|
321
|
+
outputDir = path.join(rootDir, '_site', dirPath);
|
|
322
|
+
} else {
|
|
323
|
+
// Root index file: pages/index.yaml -> _site/index.html
|
|
324
|
+
outputPath = path.join(rootDir, '_site', 'index.html');
|
|
325
|
+
outputDir = path.join(rootDir, '_site');
|
|
326
|
+
}
|
|
327
|
+
} else {
|
|
328
|
+
// Regular file: pages/test.yaml -> _site/test/index.html
|
|
329
|
+
if (dirPath && dirPath !== '.') {
|
|
330
|
+
// Nested regular file: pages/blog/post.yaml -> _site/blog/post/index.html
|
|
331
|
+
outputPath = path.join(rootDir, '_site', dirPath, pageFileName, 'index.html');
|
|
332
|
+
outputDir = path.join(rootDir, '_site', dirPath, pageFileName);
|
|
333
|
+
} else {
|
|
334
|
+
// Root level regular file: pages/test.yaml -> _site/test/index.html
|
|
335
|
+
outputPath = path.join(rootDir, '_site', pageFileName, 'index.html');
|
|
336
|
+
outputDir = path.join(rootDir, '_site', pageFileName);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
298
340
|
if (!fs.existsSync(outputDir)) {
|
|
299
341
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
300
342
|
}
|
|
@@ -305,7 +347,7 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
305
347
|
}
|
|
306
348
|
|
|
307
349
|
// Process all YAML and Markdown files in pages directory recursively
|
|
308
|
-
function processAllPages(dir, basePath = '') {
|
|
350
|
+
async function processAllPages(dir, basePath = '') {
|
|
309
351
|
const pagesDir = path.join(rootDir, 'pages');
|
|
310
352
|
const fullDir = path.join(pagesDir, basePath);
|
|
311
353
|
|
|
@@ -319,18 +361,18 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
319
361
|
|
|
320
362
|
if (item.isDirectory()) {
|
|
321
363
|
// Recursively process subdirectories
|
|
322
|
-
processAllPages(dir, relativePath);
|
|
364
|
+
await processAllPages(dir, relativePath);
|
|
323
365
|
} else if (item.isFile()) {
|
|
324
366
|
if (item.name.endsWith('.yaml')) {
|
|
325
367
|
// Process YAML file
|
|
326
368
|
const outputFileName = item.name.replace('.yaml', '.html');
|
|
327
369
|
const outputRelativePath = basePath ? path.join(basePath, outputFileName) : outputFileName;
|
|
328
|
-
processPage(itemPath, outputRelativePath, false);
|
|
370
|
+
await processPage(itemPath, outputRelativePath, false);
|
|
329
371
|
} else if (item.name.endsWith('.md')) {
|
|
330
372
|
// Process Markdown file
|
|
331
373
|
const outputFileName = item.name.replace('.md', '.html');
|
|
332
374
|
const outputRelativePath = basePath ? path.join(basePath, outputFileName) : outputFileName;
|
|
333
|
-
processPage(itemPath, outputRelativePath, true);
|
|
375
|
+
await processPage(itemPath, outputRelativePath, true);
|
|
334
376
|
}
|
|
335
377
|
// Ignore other file types
|
|
336
378
|
}
|
|
@@ -388,7 +430,7 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
388
430
|
copyStaticFiles();
|
|
389
431
|
|
|
390
432
|
// Process all pages (can overwrite static files)
|
|
391
|
-
processAllPages('');
|
|
433
|
+
await processAllPages('');
|
|
392
434
|
|
|
393
435
|
if (!quiet) console.log('Build complete!');
|
|
394
436
|
};
|