|
@@ -57,18 +57,19 @@ function createMarkdownRenderer(meta) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export async function renderMarkdownWithTemplate({
|
|
export async function renderMarkdownWithTemplate({
|
|
|
- filePath,
|
|
|
|
|
|
|
+ config,
|
|
|
meta,
|
|
meta,
|
|
|
- fileOutputPath,
|
|
|
|
|
}) {
|
|
}) {
|
|
|
|
|
+ const filePath = config.filePath
|
|
|
|
|
+ const fileOutputPath = config.fileOutputPath
|
|
|
const content = await fs.readFile(filePath, "utf8")
|
|
const content = await fs.readFile(filePath, "utf8")
|
|
|
const { data, content: markdown } = matter(content)
|
|
const { data, content: markdown } = matter(content)
|
|
|
- const templateName = data.template || meta.opts.defaultTemplate
|
|
|
|
|
|
|
+ const templateName = data.template || config.defaultTemplate
|
|
|
const href = getHref(fileOutputPath, meta)
|
|
const href = getHref(fileOutputPath, meta)
|
|
|
|
|
|
|
|
if (!templateCache.has(templateName)) {
|
|
if (!templateCache.has(templateName)) {
|
|
|
const templatePath = await firstFound(
|
|
const templatePath = await firstFound(
|
|
|
- meta.opts.templateDirs,
|
|
|
|
|
|
|
+ config.templateDirs,
|
|
|
`${templateName}.hbs`,
|
|
`${templateName}.hbs`,
|
|
|
)
|
|
)
|
|
|
if (!templatePath) throw new Error(`Template not found: ${templateName}`)
|
|
if (!templatePath) throw new Error(`Template not found: ${templateName}`)
|
|
@@ -107,14 +108,16 @@ export async function renderMarkdownWithTemplate({
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export async function compileSass({ filePath, fileOutputPath, meta }) {
|
|
|
|
|
|
|
+export async function compileSass({ config, meta }) {
|
|
|
|
|
+ const filePath = config.filePath
|
|
|
|
|
+ const fileOutputPath = config.fileOutputPath
|
|
|
const result = await sass.compileAsync(filePath, { style: "compressed" })
|
|
const result = await sass.compileAsync(filePath, { style: "compressed" })
|
|
|
await writeFile(fileOutputPath, result.css)
|
|
await writeFile(fileOutputPath, result.css)
|
|
|
return {
|
|
return {
|
|
|
paths: [fileOutputPath],
|
|
paths: [fileOutputPath],
|
|
|
ref: slugifyString(fileOutputPath),
|
|
ref: slugifyString(fileOutputPath),
|
|
|
detail: {
|
|
detail: {
|
|
|
- href: fileOutputPath.replace(meta.opts.outDir, "")
|
|
|
|
|
|
|
+ href: fileOutputPath.replace(meta.opts.outDir, ""),
|
|
|
},
|
|
},
|
|
|
deps: {
|
|
deps: {
|
|
|
paths: [...result.loadedUrls.map(item => item.pathname)],
|
|
paths: [...result.loadedUrls.map(item => item.pathname)],
|
|
@@ -122,7 +125,9 @@ export async function compileSass({ filePath, fileOutputPath, meta }) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export async function optimiseSvg({ filePath, fileOutputPath }) {
|
|
|
|
|
|
|
+export async function optimiseSvg({ config }) {
|
|
|
|
|
+ const filePath = config.filePath
|
|
|
|
|
+ const fileOutputPath = config.fileOutputPath
|
|
|
const svgString = await fs.readFile(filePath, "utf8")
|
|
const svgString = await fs.readFile(filePath, "utf8")
|
|
|
const result = optimize(svgString, {
|
|
const result = optimize(svgString, {
|
|
|
plugins: ["preset-default"],
|
|
plugins: ["preset-default"],
|
|
@@ -134,16 +139,20 @@ export async function optimiseSvg({ filePath, fileOutputPath }) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export async function copy({ filePath, fileOutputPath }) {
|
|
|
|
|
- const fileContent = await fs.readFile(filePath, "utf8")
|
|
|
|
|
- await writeFile(fileOutputPath, fileContent)
|
|
|
|
|
|
|
+export async function copy({ config }) {
|
|
|
|
|
+ const filePath = config.filePath
|
|
|
|
|
+ const fileOutputPath = config.fileOutputPath
|
|
|
|
|
+ await fs.mkdir(config.fileOutputDir, { recursive: true })
|
|
|
|
|
+ await fs.copyFile(filePath, fileOutputPath)
|
|
|
return {
|
|
return {
|
|
|
paths: [fileOutputPath],
|
|
paths: [fileOutputPath],
|
|
|
ref: slugifyString(fileOutputPath),
|
|
ref: slugifyString(fileOutputPath),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export async function imageToWebP({ filePath, meta, fileOutputDir, config }) {
|
|
|
|
|
|
|
+export async function imageToWebP({ meta, config }) {
|
|
|
|
|
+ const filePath = config.filePath
|
|
|
|
|
+ const fileOutputDir = config.fileOutputDir
|
|
|
const sourceExtension = path.extname(filePath)
|
|
const sourceExtension = path.extname(filePath)
|
|
|
const outputExtension = config.outputFileExtension
|
|
const outputExtension = config.outputFileExtension
|
|
|
const base = path.basename(filePath, sourceExtension)
|
|
const base = path.basename(filePath, sourceExtension)
|
|
@@ -177,16 +186,18 @@ export async function imageToWebP({ filePath, meta, fileOutputDir, config }) {
|
|
|
}),
|
|
}),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- const imageRef = getCleanPath(path.join(filePath), meta)
|
|
|
|
|
|
|
+ const imageRef = slugifyString(getCleanPath(path.join(filePath), meta))
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
paths: srcSet.map(src => src[0]),
|
|
paths: srcSet.map(src => src[0]),
|
|
|
- detail: { imageRef, srcSet, aspectRatio },
|
|
|
|
|
|
|
+ detail: { srcSet, aspectRatio },
|
|
|
ref: imageRef,
|
|
ref: imageRef,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export async function generateFavicons({ filePath, meta, fileOutputDir }) {
|
|
|
|
|
|
|
+export async function generateFavicons({ meta, config }) {
|
|
|
|
|
+ const filePath = config.filePath
|
|
|
|
|
+ const fileOutputDir = config.fileOutputDir
|
|
|
// Configuration for favicons package
|
|
// Configuration for favicons package
|
|
|
const configuration = {
|
|
const configuration = {
|
|
|
path: getCleanPath(fileOutputDir, meta), // Path for overriding default icons path
|
|
path: getCleanPath(fileOutputDir, meta), // Path for overriding default icons path
|