@rettangoli/sites 0.2.1 → 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 +1 -1
- package/src/createSiteBuilder.js +53 -17
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",
|
package/src/createSiteBuilder.js
CHANGED
|
@@ -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
|
|
@@ -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
|
|
@@ -298,9 +307,36 @@ export function createSiteBuilder({ fs, rootDir = '.', md, functions = {}, quiet
|
|
|
298
307
|
htmlString = convertToHtml(resultArray);
|
|
299
308
|
}
|
|
300
309
|
|
|
301
|
-
// Create output directory
|
|
302
|
-
const
|
|
303
|
-
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
|
+
|
|
304
340
|
if (!fs.existsSync(outputDir)) {
|
|
305
341
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
306
342
|
}
|