diff --git a/_EXAMPLE_config.yml b/_EXAMPLE_config.yml index 7b452ed..bf2cc9d 100644 --- a/_EXAMPLE_config.yml +++ b/_EXAMPLE_config.yml @@ -21,13 +21,13 @@ copyright: true # Display copyright # Defaults into FontAwesome if no image provided # Disables scarf if no image, and font awesome not configured scarf: - - url: / # Example Usecase for image + - url: tags/baking # Example Usecase for image image: images/assets/scarves/scarf.png icon: false enable: true - color: #fff + color: false alt: Example - - url: / # Example Usecase for FontAwesome + - url: tags/photo # Example Usecase for FontAwesome image: false icon: fa-solid fa-heart enable: true @@ -45,9 +45,9 @@ social: - url: https://www.twitch.tv/ icon: fab fa-twitch enable: false - - url: https://www.goodreads.com/ - icon: fab fa-goodreads - enable: false + - url: https://mastodon.social + icon: fab fa-mastodon + enable: true - url: https://www.linkedin.com/ icon: fab fa-linkedin enable: true @@ -81,4 +81,4 @@ sidebar_menu: - enable: true name: The Hackman Club url: https://blog.hackman.club - \ No newline at end of file + diff --git a/layout/_partial/post_feed.ejs b/layout/_partial/post_feed.ejs index 19b741e..ad69bcb 100644 --- a/layout/_partial/post_feed.ejs +++ b/layout/_partial/post_feed.ejs @@ -3,7 +3,7 @@ <% if(post.photos) { %>
<% } %> diff --git a/scripts/thumbnails.js b/scripts/thumbnails.js new file mode 100644 index 0000000..015a188 --- /dev/null +++ b/scripts/thumbnails.js @@ -0,0 +1,66 @@ +// This script was made with help of ChatGPT and adjusted to correct working state. + +const fs = require('fs'); +const path = require('path'); +const sharp = require('sharp'); + +hexo.extend.filter.register('after_init', async function() { + if (!hexo.theme.config.thumbnails) return; + if ( (hexo.env.cmd !== 'generate') && (hexo.env.cmd !== 'g') ) return; + + console.log('Generating thumbnails...'); + + const source = path.join(hexo.base_dir, 'source/images'); + const thumbnails = path.join(hexo.base_dir, 'source/thumbnails'); + + if (!fs.existsSync(thumbnails)) { + fs.mkdirSync(thumbnails, { recursive: true }); + } + + // Thumbnail sizes + const sizes = [ + { name: 'small', width: 333 }, // Three-column layout + { name: 'medium', width: 666 }, // Two-column layout + { name: 'large', width: 1000 } // Normal post + ]; + + const getAllFilesInclSubfolders = (dir) => { + let results = []; + fs.readdirSync(dir).forEach(file => { + if (file === '.' || file === '..') return; + + const fullPath = path.join(dir, file); + if (fs.statSync(fullPath).isDirectory()) { + results = results.concat(getAllFilesInclSubfolders(fullPath)); + } else { + results.push(fullPath); + } + }); + return results; + }; + + const imageFiles = getAllFilesInclSubfolders(source); + imageFiles.forEach(inputFile => { + const ext = path.extname(inputFile).toLowerCase(); + if (['.jpg', '.jpeg', '.png', '.webp'].includes(ext)) { + sizes.forEach(size => { + // Maintain folder structure in thumbnails + const relativePath = path.relative(thumbnails, inputFile).replace(/^(\.\.\/)+images\//, ''); + + const outputFile = path.join(thumbnails, size.name + '-' + relativePath); + console.log(`PARTIAL: ${inputFile} - ${relativePath}`); + + // Ensure the output directory structure exists + fs.mkdirSync(path.dirname(outputFile), { recursive: true }); + + if (!fs.existsSync(outputFile)) { + sharp(inputFile) + .resize(size.width) + .toFile(outputFile) + .then(() => console.log(`Generated: ${outputFile}`)) + .catch(err => console.error(`Error processing ${inputFile}:`, err)); + } + }); + } + }); +});