aggiunto il supporto per i linguaggi

This commit is contained in:
KillerBossOriginal 2025-02-16 21:59:27 +01:00
parent 199a19d501
commit 45c74a11b3
Signed by: KillerBossOriginal
SSH key fingerprint: SHA256:g7H+SlV+I5Mm+ycywgv2DsfeQczLXX5KtmLO5Nkj9AE
2 changed files with 56 additions and 59 deletions
.forgejo/workflows
scripts

View file

@ -1,17 +1,18 @@
name: Aggiorna index.json e aggiungilo alla Release
name: Generate Global Index on Release
on:
release:
types: [published]
jobs:
update-index:
generate-index:
runs-on: docker
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.target_commitish }}
fetch-depth: 0 # Clona tutte le branch
- name: Setup Node.js
uses: actions/setup-node@v3
@ -24,17 +25,9 @@ jobs:
- name: Genera index.json
run: npm run index
- name: Verifica modifiche in index.json
id: check_changes
run: |
if git diff --quiet index.json; then
echo "changed=false" >> $GITHUB_ENV
else
echo "changed=true" >> $GITHUB_ENV
fi
- name: Aggiungi index.json alla Release
- name: Aggiungi index.json alla release
uses: earl-warren/action-gh-release@v1
with:
files: index.json
token: ${{ secrets.GITHUB_TOKEN }}

View file

@ -1,52 +1,56 @@
const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const matter = require("gray-matter");
// Cartella base del progetto
const docsDir = path.join(__dirname, '..');
const repoDir = path.join(__dirname, "..");
const indexFile = path.join(repoDir, "index.json");
const excludedDirs = [".trash", "node_modules"];
// Nome della cartella da escludere
const excludedDir = ['.trash', "node_modules"];
// Ottieni tutte le branch disponibili
const branches = execSync("git branch -r", { encoding: "utf8" })
.split("\n")
.map(b => b.trim().replace("origin/", ""))
.filter(b => b && !b.includes("HEAD") && b !== "main");
function generateIndex() {
// Funzione ricorsiva per cercare tutti i file .md, escludendo `.trash`
function findMdFiles(dir) {
const files = fs.readdirSync(dir);
const mdFiles = [];
// Funzione per trovare file Markdown, ignorando `.trash` e `node_modules`
function findMdFiles(dir) {
const files = fs.readdirSync(dir, { withFileTypes: true });
let mdFiles = [];
files.forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
// Escludi la cartella .trash
if (!excludedDir.includes(file)) {
mdFiles.push(...findMdFiles(filePath));
}
} else if (path.extname(file) === '.md') {
// Se è un file .md, aggiungilo alla lista
mdFiles.push(filePath);
}
});
return mdFiles;
for (const file of files) {
const filePath = path.join(dir, file.name);
if (file.isDirectory() && !excludedDirs.includes(file.name)) {
mdFiles.push(...findMdFiles(filePath));
} else if (file.isFile() && file.name.endsWith(".md")) {
mdFiles.push(filePath);
}
}
// Crea l'array di oggetti per l'indice
const index = findMdFiles(docsDir).map(file => {
const content = fs.readFileSync(file, 'utf8');
const { data } = matter(content);
return {
slug: data.slug || file.replace(docsDir, '').replace(/\.md$/, '').replace(/ /g, "%20").slice(1), // Rimuove il percorso assoluto e i separatori iniziali
...data
};
}).filter(post => post.public === "true");
// Scrive l'array nel file index.json (formattato in modo leggibile)
const indexPath = path.join(__dirname, '../index.json');
fs.writeFileSync(indexPath, JSON.stringify(index, null, 2));
console.log('index.json aggiornato con successo.');
return mdFiles;
}
generateIndex();
let index = [];
branches.forEach(branch => {
console.log(`🔄 Checkout della branch: ${branch}`);
execSync(`git checkout ${branch}`, { stdio: "ignore" });
const mdFiles = findMdFiles(repoDir);
mdFiles.forEach(file => {
const content = fs.readFileSync(file, "utf8");
const { data } = matter(content);
if (data.public === "true") {
index.push({
slug: data.slug || file.replace(repoDir, "").replace(/\.md$/, "").replace(/ /g, "%20").slice(1),
language: branch, // Imposta la lingua dalla branch
...data
});
}
});
});
// Salva il file JSON con i dati
fs.writeFileSync(indexFile, JSON.stringify(index, null, 2));
console.log("✅ index.json creato con successo.");