mikser-io 6.21.3 → 6.21.4
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/engine.js +21 -1
- package/src/plugins/layouts.js +10 -1
package/package.json
CHANGED
package/src/engine.js
CHANGED
|
@@ -316,11 +316,31 @@ export async function setup(options) {
|
|
|
316
316
|
for await (const { entity, options, context, output } of useJournal('Queuing postprocess', [OPERATION.RENDER], signal)) {
|
|
317
317
|
if (output?.success && options.postprocessor) {
|
|
318
318
|
const ext = await resolveOutputExt(options.postprocessor)
|
|
319
|
+
let destination = changeExtension(entity.destination, ext)
|
|
320
|
+
|
|
321
|
+
// cleanUrls renders a non-index page `foo` to
|
|
322
|
+
// `foo/index.html` so the served URL is `/foo/`. A
|
|
323
|
+
// postprocessor that emits a *different* file type (e.g.
|
|
324
|
+
// PDF) shouldn't inherit that clean-URL folder — a
|
|
325
|
+
// downloadable artifact wants to be `foo.pdf`, not
|
|
326
|
+
// `foo/index.pdf`. Collapse the `/index` segment when the
|
|
327
|
+
// produced extension differs from the rendered page's.
|
|
328
|
+
// Genuine index documents (name ends in `index`) keep
|
|
329
|
+
// their path.
|
|
330
|
+
const originExt = path.extname(entity.destination).slice(1)
|
|
331
|
+
const isCleanUrlPage =
|
|
332
|
+
runtime.config.layouts?.cleanUrls &&
|
|
333
|
+
!_.endsWith(entity.name, 'index') &&
|
|
334
|
+
path.basename(entity.destination, path.extname(entity.destination)) === 'index'
|
|
335
|
+
if (ext !== originExt && isCleanUrlPage) {
|
|
336
|
+
destination = `${path.dirname(entity.destination)}.${ext}`
|
|
337
|
+
}
|
|
338
|
+
|
|
319
339
|
tasks.push({
|
|
320
340
|
entity: {
|
|
321
341
|
...entity,
|
|
322
342
|
origin: entity.destination,
|
|
323
|
-
destination
|
|
343
|
+
destination
|
|
324
344
|
},
|
|
325
345
|
options: { postprocessor: options.postprocessor, tasks: options.tasks },
|
|
326
346
|
context
|
package/src/plugins/layouts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { mkdir, writeFile, unlink } from 'node:fs/promises'
|
|
2
|
+
import { mkdir, writeFile, unlink, rmdir } from 'node:fs/promises'
|
|
3
3
|
import { existsSync } from 'node:fs'
|
|
4
4
|
import { globby } from 'globby'
|
|
5
5
|
import _ from 'lodash'
|
|
@@ -405,6 +405,15 @@ export default ({
|
|
|
405
405
|
try {
|
|
406
406
|
await unlink(originFile)
|
|
407
407
|
} catch { }
|
|
408
|
+
// With cleanUrls the origin was `<name>/index.html`; once
|
|
409
|
+
// the postprocessor wrote `<name>.<ext>` elsewhere, that
|
|
410
|
+
// folder is left empty. Remove it if so. rmdir only
|
|
411
|
+
// succeeds on an empty directory, so this is a no-op when
|
|
412
|
+
// the folder still holds other outputs (e.g. paginated
|
|
413
|
+
// pages).
|
|
414
|
+
try {
|
|
415
|
+
await rmdir(path.dirname(originFile))
|
|
416
|
+
} catch { }
|
|
408
417
|
}
|
|
409
418
|
}
|
|
410
419
|
})
|