generated from sofia/eleventy-base
Do not copy hashed files that already exist in dest
This commit is contained in:
parent
a60159ad68
commit
36afcaa753
2 changed files with 14 additions and 4 deletions
16
.eleventy.js
16
.eleventy.js
|
@ -2,7 +2,7 @@ import { createRequire } from "module"
|
|||
const require = createRequire(import.meta.url)
|
||||
|
||||
import { basename, dirname, extname, join, relative } from "path";
|
||||
import { copyFile, mkdir, readdir, readFile, stat, unlink } from "fs/promises";
|
||||
import { access, constants, copyFile, mkdir, readdir, readFile, stat, unlink } from "fs/promises";
|
||||
import { createHash } from "crypto";
|
||||
|
||||
import { DateTime } from "luxon";
|
||||
|
@ -64,15 +64,23 @@ async function prepareManifest(assetsPath, log = console.log) {
|
|||
: join(relDir, newBase)
|
||||
|
||||
assetsManifest[relative(assetsPath, absPath)] = newRelPath
|
||||
log(`[sofi-assets] Manifest: '${absPath}' to '${newRelPath}'`)
|
||||
}
|
||||
}
|
||||
|
||||
async function fileExists(path) {
|
||||
return await access(path, constants.F_OK).then(() => true, () => false);
|
||||
}
|
||||
|
||||
async function processAssets(assetsPath, outputPath, log = console.log) {
|
||||
for (const [origRel, newRel] of Object.entries(assetsManifest)) {
|
||||
const src = join(assetsPath, origRel);
|
||||
const dest = join(outputPath, newRel);
|
||||
|
||||
if (basename(dest, extname(dest)).endsWith("__h") && await fileExists(dest)) {
|
||||
log(`[sofi-assets] Skipped copying '${src}' because it already exists as '${dest}'`)
|
||||
continue
|
||||
}
|
||||
|
||||
await mkdir(dirname(dest), { recursive: true })
|
||||
|
||||
await copyFile(src, dest);
|
||||
|
@ -116,9 +124,11 @@ function dateDesc(a, b) {
|
|||
export default async function (eleventyConfig) {
|
||||
const log = eleventyConfig.logger.log.bind(eleventyConfig.logger)
|
||||
|
||||
eleventyConfig.addPassthroughCopy({ "assets/robots.txt": "robots.txt" })
|
||||
|
||||
eleventyConfig.addWatchTarget("./assets/")
|
||||
eleventyConfig.on("eleventy.before", async () => {
|
||||
prepareManifest("assets", log)
|
||||
await prepareManifest("assets", log)
|
||||
})
|
||||
|
||||
eleventyConfig.on("eleventy.after", async () => {
|
||||
|
|
|
@ -14,4 +14,4 @@ a/xLBCS5BgMBCAfCfgQYFgoAJhYhBKEVU9yTYwhnuD7hKloUhbTMzdtKBQJneV6n
|
|||
AhsMBQkDwmcAAAoJEFoUhbTMzdtK72kA/0JKzhX51gN4YPrsCL3Qc3+kDlR0xG4z
|
||||
kpeXX7gk1Y7ZAQDagUM1PCkb7vT6stQsPuuhdyvXsYcvWtV15uxPbITUAg==
|
||||
=b5x3
|
||||
-----END PGP PUBLIC KEY BLOCK----
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
Loading…
Reference in a new issue