Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/check-image-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check Image Cache

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 4'

jobs:
check-images-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache images
id: images-cache
uses: actions/cache@v4
env:
cache-name: cache-images
with:
path: '.cache/@11ty/_images'
enableCrossOsArchive: true
key: images-${{ hashFiles('src/articles/**/*.png', 'src/articles/**/*.jpg', 'src/articles/**/*.svg', 'src/articles/**/*.gif', 'src/people/**/*.jpg') }}
- name: check cache
if: steps.images-cache.outputs.cache-hit != 'true'
shell: bash
run: echo "Кэш изображений не найден
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В команде shell отсутствует закрывающая кавычка, из-за чего шаг завершится ошибкой синтаксиса. Закройте кавычку.

Suggested change
run: echo "Кэш изображений не найден
run: echo "Кэш изображений не найден"

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут, пожалуй, соглашусь )

Comment on lines +13 to +25
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Восстановление кэша не продлевает срок его жизни в GitHub Actions; TTL обновляется только при сохранении. Текущий workflow по расписанию не перезапишет кэш (на cache-hit сохранения не происходит), поэтому не продлит TTL. Решение: используйте пары actions/cache/restore и actions/cache/save с «роллирующим» ключом (например, с префиксом images-${{ HASH }}- и суффиксом, зависящим от недели), и измените restore на использование restore-keys, чтобы сборка могла брать последний сохраненный вариант.

Suggested change
- name: Cache images
id: images-cache
uses: actions/cache@v4
env:
cache-name: cache-images
with:
path: '.cache/@11ty/_images'
enableCrossOsArchive: true
key: images-${{ hashFiles('src/articles/**/*.png', 'src/articles/**/*.jpg', 'src/articles/**/*.svg', 'src/articles/**/*.gif', 'src/people/**/*.jpg') }}
- name: check cache
if: steps.images-cache.outputs.cache-hit != 'true'
shell: bash
run: echo "Кэш изображений не найден
- name: Compute cache hash
id: cache-hash
run: echo "hash=$(git ls-files src/articles/**/*.png src/articles/**/*.jpg src/articles/**/*.svg src/articles/**/*.gif src/people/**/*.jpg | xargs sha256sum | sha256sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
- name: Get week number
id: week
run: echo "week=$(date +%V)" >> $GITHUB_OUTPUT
- name: Restore images cache
id: images-cache-restore
uses: actions/cache/restore@v4
with:
path: '.cache/@11ty/_images'
enableCrossOsArchive: true
key: images-${{ steps.cache-hash.outputs.hash }}-week-${{ steps.week.outputs.week }}
restore-keys: |
images-${{ steps.cache-hash.outputs.hash }}-
- name: check cache
if: steps.images-cache-restore.outputs.cache-hit != 'true'
shell: bash
run: echo "Кэш изображений не найден"
- name: Save images cache
if: always()
uses: actions/cache/save@v4
with:
path: '.cache/@11ty/_images'
enableCrossOsArchive: true
key: images-${{ steps.cache-hash.outputs.hash }}-week-${{ steps.week.outputs.week }}

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В документации Github'а сказано про "accessed". Так что лучше проверить самим через неделю-другую.

7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: package.json
- name: Images cache
id: images-cache
uses: actions/cache@v4
with:
path: '.cache/@11ty/_images'
enableCrossOsArchive: true
key: images-${{ hashFiles('src/articles/**/*.png', 'src/articles/**/*.jpg', 'src/articles/**/*.svg', 'src/articles/**/*.gif', 'src/people/**/*.jpg') }}
# Setup key
- name: Setup key
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
.cache
22 changes: 10 additions & 12 deletions src/eleventy-config/transforms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path';
import os from 'node:os';
import fs from 'node:fs';
import htmlmin from 'html-minifier-terser';
import minifyXml from 'minify-xml';
import { parseHTML } from 'linkedom';
Expand All @@ -11,12 +12,9 @@ const isProdMode = process.env.NODE_ENV === 'production';

async function processImage({ imageElement, inputPath, options, attributes }) {
const imageStats = await Image(inputPath, {
filenameFormat: (hash, src, width, format) => {
const extension = path.extname(src);
const name = path.basename(src, extension);
return `${hash}-${name}-${width}.${format}`;
},
...options,
outputDir: '.cache/@11ty/_images',
urlPath: '/_images/',
...options
});

const imageAttributes = Object.assign(
Expand Down Expand Up @@ -53,7 +51,6 @@ export default function(eleventyConfig) {
}

const articleSourceFolder = path.dirname(this.page.inputPath);
const outputArticleImagesFolder = path.join(path.dirname(this.page.outputPath), 'images');

await Promise.all(images.map(async(image) => {
const fullImagePath = path.join(articleSourceFolder, image.src);
Expand All @@ -69,8 +66,6 @@ export default function(eleventyConfig) {
formats: isProdMode && !isGif
? ['svg', 'avif', 'webp', 'auto']
: ['svg', 'webp', 'auto'],
outputDir: outputArticleImagesFolder,
urlPath: 'images/',
svgShortCircuit: true,
sharpOptions: {
animated: true,
Expand Down Expand Up @@ -108,7 +103,6 @@ export default function(eleventyConfig) {

await Promise.all(images.map(async(image) => {
const fullImagePath = path.join(eleventyConfig.dir.input, image.src);
const avatarsOutputFolder = path.dirname(path.join(eleventyConfig.dir.output, image.src));

await processImage({
imageElement: image,
Expand All @@ -124,8 +118,6 @@ export default function(eleventyConfig) {
formats: isProdMode
? ['svg', 'avif', 'webp', 'auto']
: ['svg', 'webp', 'auto'],
outputDir: avatarsOutputFolder,
urlPath: image.src.split('/').slice(0, -1).join('/'),
svgShortCircuit: true,
},
});
Expand All @@ -134,6 +126,12 @@ export default function(eleventyConfig) {
return document.toString();
});

eleventyConfig.on('eleventy.after', () => {
const from = '.cache/@11ty/_images/';
const to = path.join(eleventyConfig.directories.output, '_images');
fs.cpSync(from, to, { recursive: true });
});

eleventyConfig.addTransform('lazyYouTube', (content, outputPath) => {
let articles = /articles\/([a-zA-Z0-9_-]+)\/index\.html/i;
let iframes = /<iframe src="https:\/\/www\.youtube\.com\/embed\/([a-zA-Z0-9_-]+)"(.*?)><\/iframe>/ig;
Expand Down