37 Commits 9691df4462 ... a1629dbd1d

Author SHA1 Message Date
  Craig Fletcher a1629dbd1d Fix multiple found issues/bugs 3 months ago
  Craig Fletcher 9691df4462 Add taxonomy, splitting 3 months ago
  Craig Fletcher 02973cb20e Add taxonomy, splitting 3 months ago
  Craig Fletcher 66cf94a211 Add index/listing 3 months ago
  Craig Fletcher 4d8c446ca9 Add index/listing 3 months ago
  Craig Fletcher 557b05b05b Add config override switch 4 months ago
  Craig Fletcher 58cd0190f3 Add config override switch 4 months ago
  Craig Fletcher d580801284 Refactor: break up utils 10 months ago
  Craig Fletcher cdaeb20e1d Refactor: break up utils 10 months ago
  Craig Fletcher 8916410d6c Added support for includes, early content rendering 10 months ago
  Craig Fletcher 826a68c8e5 Added support for includes, early content rendering 10 months ago
  Craig Fletcher a212e95446 Refactoring cache 10 months ago
  Craig Fletcher b1094f1256 Refactoring cache 10 months ago
  Craig Fletcher d5afbf6745 Update README.md with latest changes 10 months ago
  Craig Fletcher a8a53d29df Update README.md with latest changes 10 months ago
  Craig Fletcher f37688df55 Refactor caching, processor API and logging 10 months ago
  Craig Fletcher c09be89e1f Refactor caching, processor API and logging 10 months ago
  Craig Fletcher 3b580f85ed Refactoring processor API 10 months ago
  Craig Fletcher 368ec35586 Refactoring processor API 10 months ago
  Craig Fletcher 25d74c862f Logging, minor refactoring 10 months ago
  Craig Fletcher 0526a7a333 Logging, minor refactoring 10 months ago
  Craig Fletcher 1a4361527a Add cache support 10 months ago
  Craig Fletcher 288742b973 Add cache support 10 months ago
  Craig Fletcher 995d621c06 Refactor: dir listing to glob for infiles 10 months ago
  Craig Fletcher 265f7a126f Refactor: dir listing to glob for infiles 10 months ago
  Craig Fletcher 615ea13928 Meta support 10 months ago
  Craig Fletcher f3480b0b3a Meta support 10 months ago
  Craig Fletcher 4758c2c7fa Add favicon and metadata generation 10 months ago
  Craig Fletcher 8781b19fbc Add favicon and metadata generation 10 months ago
  Craig Fletcher 8233d7aca0 Refactor and tidy: 10 months ago
  Craig Fletcher 46612e618d Refactor and tidy: 10 months ago
  Craig Fletcher 5835cc9815 Add image optimisation 10 months ago
  Craig Fletcher 44921a7056 Add image optimisation 10 months ago
  Craig Fletcher c1d966cfb9 Add support for multiple paths on inputs and templates 1 year ago
  Craig Fletcher 319cf68c30 Add support for multiple paths on inputs and templates 1 year ago
  Craig Fletcher 5937e76daa Initial commit 1 year ago
  Craig Fletcher c298eaa953 Initial commit 1 year ago
5 changed files with 33 additions and 21 deletions
  1. 8 7
      src/cache.js
  2. 1 0
      src/defaults.js
  3. 10 1
      src/logging.js
  4. 13 12
      src/processors.js
  5. 1 1
      src/util/file-system.js

+ 8 - 7
src/cache.js

@@ -11,24 +11,25 @@ import {
   getDeepestPropertiesForKey,
 } from "./util/index.js"
 
+const objectHashCache = new Map()
 export function hashObject(obj) {
   const str = stableStringify(obj)
-  if (!hashCache.has(str)) {
+  if (!objectHashCache.has(str)) {
     const hashString = createHash("md5")
       .update(str)
       .digest("hex")
-    hashCache.set(str, hashString)
+    objectHashCache.set(str, hashString)
     return hashString
   } else {
-    const cachedHashString = hashCache.get(str)
+    const cachedHashString = objectHashCache.get(str)
     return cachedHashString
   }
 }
 
-const hashCache = new Map()
+const fileHashCache = new Map()
 export async function getFileHash(filePath, algorithm = "md5") {
   return new Promise((resolve, reject) => {
-    if (!hashCache.has(filePath)) {
+    if (!fileHashCache.has(filePath)) {
       const hash = createHash(algorithm)
       const stream = createReadStream(filePath)
 
@@ -36,11 +37,11 @@ export async function getFileHash(filePath, algorithm = "md5") {
       stream.on("data", chunk => hash.update(chunk))
       stream.on("end", () => {
         const hashString = hash.digest("hex")
-        hashCache.set(filePath, hashString)
+        fileHashCache.set(filePath, hashString)
         resolve(hashString)
       })
     } else {
-      const cachedHashString = hashCache.get(filePath)
+      const cachedHashString = fileHashCache.get(filePath)
       resolve(cachedHashString)
     }
   })

+ 1 - 0
src/defaults.js

@@ -101,6 +101,7 @@ export const tasks = [
       processor: renderTemplate,
       writeOut: true,
       templateDirs: ["templates/", "~/.rhedyn/templates/"],
+      defaultTemplate: "page",
     },
     {
       name: "render indexes",

+ 10 - 1
src/logging.js

@@ -117,6 +117,15 @@ export function getLogger(logLevel = "info", name) {
         warn: noop,
         error: noop,
       }
-
+    default:
+      return {
+        group: console.group,
+        groupEnd: console.groupEnd,
+        trace: noop,
+        debug: noop,
+        info: logMessage("info", label),
+        warn: logMessage("warn", label),
+        error: logMessage("error", label),
+      }
   }
 }

+ 13 - 12
src/processors.js

@@ -74,9 +74,10 @@ async function getTemplate(templatePath) {
 }
 
 export async function renderTemplate({ config, meta }) {
+  const templateName = config.template || config.defaultTemplate
   const templatePath =
     config.filePath ||
-    (await findTemplatePath(config.templateDirs, config.template))
+    (await findTemplatePath(config.templateDirs, templateName))
   const fileOutputPath = config.fileOutputPath
   const href = getHref(fileOutputPath, meta)
 
@@ -239,7 +240,8 @@ export async function imageToWebP({ meta, config }) {
   }
 
   const aspectRatio = width / height
-  const name = config.uniqueFilenames ? base : `${base}-${generateRandomId()}`
+  const name = config.uniqueFilenames ? `${base}-${generateRandomId()}` : base
+  const outputFiles = []
   const srcSet = await Promise.all(
     config.imageSizes.map(async size => {
       const sizeNum = parseInt(size.replace("w", ""), 10)
@@ -254,6 +256,7 @@ export async function imageToWebP({ meta, config }) {
         .webp({ quality: config.quality })
         .toFile(outputFile)
 
+      outputFiles.push(outputFile)
       return [getCleanPath(outputFile, meta), size]
     }),
   )
@@ -261,7 +264,7 @@ export async function imageToWebP({ meta, config }) {
   const imageRef = slugifyString(getCleanPath(path.join(filePath), meta))
 
   return {
-    paths: srcSet.map(src => src[0]),
+    paths: outputFiles,
     detail: { srcSet, aspectRatio },
     ref: imageRef,
   }
@@ -279,7 +282,7 @@ export async function generateFavicons({ meta, config }) {
     developerName: meta.opts.site?.author || "",
     developerURL: meta.opts.site?.url || "",
     dir: "auto",
-    lang: meta.opts.site?.language | "en-US",
+    lang: meta.opts.site?.language || "en-US",
     background: meta.opts.site?.backgroundColor || "#ffffff",
     theme_color: meta.opts.site?.themeColor || "#ffffff",
     appleStatusBarStyle: "black-translucent",
@@ -327,12 +330,8 @@ export async function generateFavicons({ meta, config }) {
         htmlMeta,
       },
       paths: [
-        ...response.images.map(img =>
-          getCleanPath(path.join(fileOutputDir, img.name), meta),
-        ),
-        ...response.files.map(file =>
-          getCleanPath(path.join(fileOutputDir, file.name), meta),
-        ),
+        ...response.images.map(img => path.join(fileOutputDir, img.name)),
+        ...response.files.map(file => path.join(fileOutputDir, file.name)),
       ],
       ref: config.name,
     }
@@ -343,14 +342,16 @@ export async function generateFavicons({ meta, config }) {
 
 export async function generateTaxonomy({ config }) {
   const allValues = config.inputs.reduce((values, curr) => {
-    return values.union(new Set(curr[config.indexOn]))
+    const items = curr[config.indexOn] || []
+    items.forEach(v => values.add(v))
+    return values
   }, new Set())
   const orderBy = config.orderBy || "date"
   const sortedInputs = config.sortAscending
     ? _.sortBy(config.inputs, orderBy)
     : _.sortBy(config.inputs, orderBy).reverse()
   const taxonomy = config.indexOn
-    ? allValues.values().reduce((groups, currentGroup) => {
+    ? [...allValues.values()].reduce((groups, currentGroup) => {
       const grouped = {
         ...groups,
         [currentGroup]: sortedInputs

+ 1 - 1
src/util/file-system.js

@@ -24,7 +24,7 @@ export async function readDirectoryRecursively(dir, files = []) {
   for (const item of contents) {
     const itemPath = path.join(dir, item.name)
     if (item.isDirectory()) {
-      readDirectoryRecursively(itemPath, files)
+      await readDirectoryRecursively(itemPath, files)
     } else {
       files.push(itemPath)
     }