Last active
May 1, 2021 09:17
-
-
Save mistic100/794319529c410e15ecd6325131602d47 to your computer and use it in GitHub Desktop.
Revisions
-
mistic100 renamed this gist
May 1, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mistic100 renamed this gist
May 1, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mistic100 revised this gist
May 10, 2018 . No changes.There are no files selected for viewing
-
mistic100 created this gist
May 10, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Gallery generator for [Phugo](https://github.com/aerohub/phugo) For each directory in `content` it generates or updates the `_index.md` file with the list of all JPG files in the directory. If `_index.md` already exists, it's metadata will be kept, the rest is overwritten. If the metadata of the `_index.md` file contains `manual: true`, the directory is ignored. The thumbnails must be named by the original name prefixed by `_th_`. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ const fs = require('fs'); fs.readdirSync('content') .filter(entry => fs.statSync(`content/${entry}`).isDirectory()) .forEach(dir => { let files = fs.readdirSync(`content/${dir}`) .filter(file => file.endsWith('.jpg')) .filter(file => !file.startsWith('_th_')); let content; if (fs.existsSync(`content/${dir}/_index.md`)) { const lines = fs.readFileSync(`content/${dir}/_index.md`, {encoding : 'utf8'}).split('\n'); if (lines.indexOf('manual: true') !== -1) { return; } const headerEnd = lines.lastIndexOf('---'); content = lines.slice(0, headerEnd + 1).join('\n'); } else { content = `--- title: "${dir}" albumthumb: "${dir}/_th_${files[0]}" date: ${new Date().toISOString()} ---`; } content+= '\n\n'; content+= files .map(file => `{{< photo full="${file}" thumb="_th_${file}" >}}`) .join('\n'); content+= '\n'; fs.writeFileSync(`content/${dir}/_index.md`, content, {encoding : 'utf8'}); });