From fa71a1c61f9e210039c2cc28e40a792106805153 Mon Sep 17 00:00:00 2001 From: Bashynx Date: Wed, 24 Sep 2025 20:23:23 +0300 Subject: [PATCH] Simplified and fixed thumbnail issues --- layout/_partial/article.ejs | 2 +- layout/_partial/post_feed.ejs | 2 +- scripts/thumbnails.js | 39 ++++++++++++++--------------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/layout/_partial/article.ejs b/layout/_partial/article.ejs index 09ba1f1..21a2f4b 100644 --- a/layout/_partial/article.ejs +++ b/layout/_partial/article.ejs @@ -4,7 +4,7 @@

<%= page.title || "Untitled" %>

<% if(page.photos) { %>
- <%- page.title || "> + <%- page.title || ">
<% } %>

<%= page.description %>

diff --git a/layout/_partial/post_feed.ejs b/layout/_partial/post_feed.ejs index 7ebee5c..27112d1 100644 --- a/layout/_partial/post_feed.ejs +++ b/layout/_partial/post_feed.ejs @@ -3,7 +3,7 @@ <% if(post.photos) { %>
- <%- post.title || 'Untitled' %> + <%- post.title || 'Untitled' %>
<% } %> diff --git a/scripts/thumbnails.js b/scripts/thumbnails.js index 9f19be1..055fd6b 100644 --- a/scripts/thumbnails.js +++ b/scripts/thumbnails.js @@ -5,7 +5,6 @@ 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...'); @@ -17,12 +16,6 @@ hexo.extend.filter.register('after_init', async function() { fs.mkdirSync(thumbnails, { recursive: true }); } - // Thumbnail sizes - const sizes = [ - { name: 'small', width: 512 }, // Three-column layout - { name: 'large', width: 1024 } // Normal post - ]; - const getAllFilesInclSubfolders = (dir) => { let results = []; fs.readdirSync(dir).forEach(file => { @@ -42,24 +35,22 @@ hexo.extend.filter.register('after_init', async function() { 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\//, ''); + // 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)); - } - }); + const outputFile = path.join(thumbnails, 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(512) + .toFile(outputFile) + .then(() => console.log(`Generated: ${outputFile}`)) + .catch(err => console.error(`Error processing ${inputFile}:`, err)); + } } }); });