From edf25f65ce5c19cd62e179e22a4f01a8e8f81cd3 Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 21 Jan 2025 15:13:34 +0400 Subject: [PATCH] testing new build time --- .github/workflows/main.yml | 9 ++ gridsome.server.js | 219 ++++++++++++++++-------------- src/components/books/BookItem.vue | 2 +- 3 files changed, 129 insertions(+), 101 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 108b5af492c..76c7da1c9f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,11 +25,20 @@ jobs: with: node-version: "18.x" + - name: Get Updated Files + id: changes + run: | + git diff --name-only HEAD~1 HEAD > updated_files.txt + cat updated_files.txt + - name: Install and Build 🔧 run: | sudo npm install --global @gridsome/cli npm ci export NODE_OPTIONS="--max_old_space_size=4096" + echo "Updated files: $(cat updated_files.txt)" + UPDATED_FILES=$(cat updated_files.txt) + echo $UPDATED_FILES gridsome build env: FORM_SCRIPT: ${{ secrets.FORM_SCRIPT }} diff --git a/gridsome.server.js b/gridsome.server.js index 32901df00f0..13991e479ba 100644 --- a/gridsome.server.js +++ b/gridsome.server.js @@ -1,123 +1,142 @@ -// Server API makes it possible to hook into various parts of Gridsome -// on server-side and add custom data to the GraphQL data layer. -// Learn more: https://gridsome.org/docs/server-api/ - -// Changes here require a server restart. -// To restart press CTRL + C in terminal and run `gridsome develop` - const fs = require('fs'); -const translateBlogPost = require("./functions/translations"); -const proxy = require("http-proxy-middleware") +const translateBlogPost = require('./functions/translations'); let allPossiblePaths = []; -module.exports = function (api) { - +module.exports = function (api) { // Use the Data Store API here: https://gridsome.org/docs/data-store-api/ - api.loadSource(async store => { - store.addMetadata('home', 'https://robonomics.network') - store.addMetadata('discord', 'https://discord.gg/JpaN2XAmqY') - store.addMetadata('twitter', 'https://twitter.com/AIRA_Robonomics') - - }) + api.loadSource(async (store) => { + store.addMetadata('home', 'https://robonomics.network'); + store.addMetadata('discord', 'https://discord.gg/JpaN2XAmqY'); + store.addMetadata('twitter', 'https://twitter.com/AIRA_Robonomics'); + }); api.loadSource(async (actions) => { - - const collection = actions.getCollection('Post'); - - collection.data().filter((e) => { - if(e.locale === 'en') - allPossiblePaths.push({path: e.path, name: e.fileInfo.name, content: e.content, title: e.title, description: e.description, cover_image: e.cover_image, abstract: e.abstract, author: e.author, tags: e.tags, related: e.related, published: e.published, id: e.id}) - }) - - }) + const collection = actions.getCollection('Post'); + + // Detect updated files from the UPDATED_FILES environment variable + const updatedFiles = process.env.UPDATED_FILES + ? process.env.UPDATED_FILES.split('\n') + : null; + + collection.data().filter((e) => { + if (e.locale === 'en') { + // Filter posts if incremental build is enabled + if ( + !updatedFiles || // If UPDATED_FILES is null, include all posts + updatedFiles.some((filePath) => + filePath.endsWith(`${e.fileInfo.name}.md`) + ) + ) { + allPossiblePaths.push({ + path: e.path, + name: e.fileInfo.name, + content: e.content, + title: e.title, + description: e.description, + cover_image: e.cover_image, + abstract: e.abstract, + author: e.author, + tags: e.tags, + related: e.related, + published: e.published, + id: e.id, + }); + } + } + }); + }); // Use the Pages API here: https://gridsome.org/docs/pages-api/ - api.createManagedPages( ({ createPage }) => { - - // all locales - const locales = ["ar","de","el","en","es","fr","it","ja","ko","nl","pt","ru","uk","zh"]; - - createPage( - { - path: '/en/', - component: 'src/pages/redirect.vue', - context: { - redirect: '/' - } - } - ) + api.createManagedPages(({ createPage }) => { + // Define locales + const locales = [ + 'ar', + 'de', + 'el', + 'en', + 'es', + 'fr', + 'it', + 'ja', + 'ko', + 'nl', + 'pt', + 'ru', + 'uk', + 'zh', + ]; + + // Static redirects + createPage({ + path: '/en/', + component: 'src/pages/redirect.vue', + context: { + redirect: '/', + }, + }); - createPage( - { - path: `/white-paper-2022`, - component: 'src/pages/redirect.vue', - context: { - redirect: '/white-paper' - } - } - ) + createPage({ + path: '/white-paper-2022', + component: 'src/pages/redirect.vue', + context: { + redirect: '/white-paper', + }, + }); - createPage( - { - path: `/shop`, - component: 'src/pages/redirect.vue', - context: { - redirect: '/merch' - } - } - ) + createPage({ + path: `/shop`, + component: 'src/pages/redirect.vue', + context: { + redirect: '/merch', + }, + }); createPage({ path: `/robonomics_white_paper_en.pdf/`, component: 'src/pages/redirect.vue', context: { - redirect: '/white-paper' - } - }) + redirect: '/white-paper', + }, + }); - locales.forEach(l => { - createPage( - { - path: `/${l}/white-paper-2022`, - component: 'src/pages/redirect.vue', - context: { - redirect: '/white-paper' - } - } - ) + // Localized redirects + locales.forEach((l) => { + createPage({ + path: `/${l}/white-paper-2022`, + component: 'src/pages/redirect.vue', + context: { + redirect: '/white-paper', + }, + }); createPage({ path: `/${l}/shop`, component: 'src/pages/redirect.vue', context: { - redirect: '/merch' + redirect: '/merch', + }, + }); + }); + + // Blog posts and translations + allPossiblePaths.forEach((node) => { + const path = node.path.slice(0, -1).split('/').pop(); + + // For blog post translations + // translateBlogPost(fs, path); + + // Create pages for missing translations + locales.forEach((locale) => { + if (fs.existsSync(`content/posts/${locale}/${node.name}.md`)) { + console.log('exists'); + } else { + createPage({ + path: `/blog/${locale}/${path}`, + component: './src/templates/BlogTranslations.vue', + }); } - }) - }) - - - allPossiblePaths.forEach(node => { - - const path = node.path.slice(0, -1).split("/").pop(); - - // for blog posts translations - // translateBlogPost(fs, path) - - // pages for not existing translations - locales.forEach(locale => { - if (fs.existsSync(`content/posts/${locale}/${node.name}.md`)) { - console.log('exists'); - } else { - createPage({ - path: `/blog/${locale}/${path}`, - component: './src/templates/BlogTranslations.vue', - }) - } - }); - - - }) - }) - -} + }); + }); + }); +}; diff --git a/src/components/books/BookItem.vue b/src/components/books/BookItem.vue index b3ceea2ad1e..b1f346fcd2b 100644 --- a/src/components/books/BookItem.vue +++ b/src/components/books/BookItem.vue @@ -13,7 +13,7 @@ {{ link.text }}