diff options
-rw-r--r-- | src/data/yaml.js | 28 | ||||
-rw-r--r-- | src/util/io.js | 9 |
2 files changed, 28 insertions, 9 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js index 367876be..2c3c988d 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -62,9 +62,9 @@ export const FLASH_DATA_FILE = 'flashes.yaml'; export const NEWS_DATA_FILE = 'news.yaml'; export const ART_TAG_DATA_FILE = 'tags.yaml'; export const GROUP_DATA_FILE = 'groups.yaml'; -export const STATIC_PAGE_DATA_FILE = 'static-pages.yaml'; export const DATA_ALBUM_DIRECTORY = 'album'; +export const DATA_STATIC_PAGE_DIRECTORY = 'static-page'; // --> Document processing functions @@ -670,10 +670,10 @@ export const dataSteps = [ files: async (dataPath) => ( await findFiles(path.join(dataPath, DATA_ALBUM_DIRECTORY), { - filter: (f) => path.extname(f) === '.yaml', + filter: f => path.extname(f) === '.yaml', joinParentDirectory: false, }) - ).map((file) => path.join(DATA_ALBUM_DIRECTORY, file)), + ).map(file => path.join(DATA_ALBUM_DIRECTORY, file)), documentMode: documentModes.headerAndEntries, processHeaderDocument: processAlbumDocument, @@ -913,10 +913,16 @@ export const dataSteps = [ }, { - title: `Process static pages file`, - file: STATIC_PAGE_DATA_FILE, + title: `Process static page files`, + files: async (dataPath) => + ( + await findFiles(path.join(dataPath, DATA_STATIC_PAGE_DIRECTORY), { + filter: f => path.extname(f) === '.yaml', + joinParentDirectory: false, + }) + ).map(file => path.join(DATA_STATIC_PAGE_DIRECTORY, file)), - documentMode: documentModes.allInOne, + documentMode: documentModes.onePerFile, processDocument: processStaticPageDocument, save(staticPageData) { @@ -1021,11 +1027,17 @@ export async function loadAndProcessDataDocuments({dataPath}) { ); } - const files = ( + let files = ( typeof dataStep.files === 'function' ? await callAsync(dataStep.files, dataPath) : dataStep.files - ).map((file) => path.join(dataPath, file)); + ) + + if (!files) { + return; + } + + files = files.map((file) => path.join(dataPath, file)); const readResults = await mapAsync( files, diff --git a/src/util/io.js b/src/util/io.js index 4a6e95f3..cfd6708d 100644 --- a/src/util/io.js +++ b/src/util/io.js @@ -10,7 +10,14 @@ export async function findFiles(dataPath, { filter = () => true, joinParentDirectory = true, } = {}) { - return (await readdir(dataPath)) + let files; + try { + files = await readdir(dataPath); + } catch (error) { + throw new AggregateError([error], `Failed to list files from ${dataPath}`); + } + + return files .filter((file) => filter(file)) .map((file) => (joinParentDirectory ? path.join(dataPath, file) : file)); } |