Skip to content

Commit

Permalink
Merge pull request #422 from zirreal/master
Browse files Browse the repository at this point in the history
testing new build time
  • Loading branch information
zirreal authored Jan 21, 2025
2 parents 055ca73 + edf25f6 commit b6368e6
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 101 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
219 changes: 119 additions & 100 deletions gridsome.server.js
Original file line number Diff line number Diff line change
@@ -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',
})
}
});


})
})

}
});
});
});
};
2 changes: 1 addition & 1 deletion src/components/books/BookItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<g-link
v-for="link in book.options"
:key="link.id"
:to="booksLinks[link.name] || '#'"
:to="booksLinks[link.name] || link.static"
>
{{ link.text }}
</g-link>
Expand Down

0 comments on commit b6368e6

Please sign in to comment.