lower case #428
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple workflow for deploying static content to GitHub Pages | |
name: Compile Extensions and Deploy to Pages | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["main"] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
compile-and-deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Compile Extensions Data | |
id: compile | |
run: | | |
node -e ' | |
const fs = require("fs"); | |
const path = require("path"); | |
const { execSync } = require("child_process"); | |
// Read files from directories | |
const featuredDir = "featured"; | |
const filesDir = "files"; | |
const imagesDir = "images"; | |
const versionsFile = "versions.json"; | |
const previousVersionsFile = "cache/previous_versions.json"; | |
const templateFile = "original.html"; // Changed from index.html to original.html | |
const outputFile = "index.html"; // This will be our output file | |
// Read current versions data | |
const versions = JSON.parse(fs.readFileSync(versionsFile, "utf8")); | |
// Initialize previous versions or load if exists | |
let previousVersions = {}; | |
try { | |
if (fs.existsSync(previousVersionsFile)) { | |
previousVersions = JSON.parse(fs.readFileSync(previousVersionsFile, "utf8")); | |
} | |
} catch (e) { | |
console.log("Could not read previous versions, initializing empty object"); | |
} | |
// Ensure cache directory exists | |
if (!fs.existsSync("cache")) { | |
fs.mkdirSync("cache", { recursive: true }); | |
} | |
// Find new and updated extensions | |
const extensionStatus = {}; | |
for (const [ext, version] of Object.entries(versions)) { | |
if (!previousVersions[ext]) { | |
extensionStatus[ext] = "new"; | |
} else if (previousVersions[ext] !== version) { | |
extensionStatus[ext] = "updated"; | |
} | |
} | |
// Save current versions as previous for next time | |
fs.writeFileSync(previousVersionsFile, JSON.stringify(versions, null, 2)); | |
// Get featured files data | |
const featuredFiles = fs.readdirSync(featuredDir) | |
.filter(file => file.endsWith(".js")) | |
.map(file => { | |
const filePath = path.join(featuredDir, file); | |
const stats = fs.statSync(filePath); | |
return { | |
name: file, | |
path: filePath, | |
download_url: `https://extensions.mistium.com/${filePath}`, | |
size: stats.size, | |
status: extensionStatus[file] || "" | |
}; | |
}); | |
// Get regular files data | |
const regularFiles = fs.readdirSync(filesDir) | |
.filter(file => file.endsWith(".js")) | |
.map(file => { | |
const filePath = path.join(filesDir, file); | |
const stats = fs.statSync(filePath); | |
return { | |
name: file, | |
path: filePath, | |
download_url: `https://extensions.mistium.com/${filePath}`, | |
size: stats.size, | |
status: extensionStatus[file] || "" | |
}; | |
}); | |
// Read the original.html template | |
let indexHtml = fs.readFileSync(templateFile, "utf8"); | |
// Find the script part that needs to be replaced | |
const scriptStartIndex = indexHtml.indexOf("// Function to fetch data from GitHub API"); | |
const scriptEndIndex = indexHtml.indexOf("// Function to generate other extension gallery links"); | |
if (scriptStartIndex !== -1 && scriptEndIndex !== -1) { | |
// Create replacement script | |
const newScript = `// Function to get pre-compiled extension data | |
function fetchData() { | |
return Promise.resolve({ | |
featured: ${JSON.stringify(featuredFiles)}, | |
files: ${JSON.stringify(regularFiles)} | |
}); | |
} | |
// Function to get version data | |
function fetchAndCacheVersions() { | |
return Promise.resolve(${JSON.stringify(versions)}); | |
} | |
// Function to generate profile cards | |
async function generateProfileCards() { | |
const featuredCardsContainer = document.getElementById("featuredCards"); | |
const fileCardsContainer = document.getElementById("fileCards"); | |
const data = await fetchData(); | |
if (!data || !data.featured || !Array.isArray(data.featured) || !data.files || !Array.isArray(data.files)) return; | |
data.featured.forEach(item => { | |
const itemName = item.name.split(".")[0]; // Remove file extension | |
const isJsFile = item.name.endsWith(".js"); | |
if (isJsFile) { | |
const profileCardLink = document.createElement("a"); | |
profileCardLink.href = item.download_url; | |
profileCardLink.target = "_blank"; | |
profileCardLink.rel = "noopener noreferrer"; | |
profileCardLink.classList.add("gallery-link"); | |
const profileCard = document.createElement("div"); | |
profileCard.classList.add("profile-card"); | |
const cardContent = document.createElement("div"); | |
cardContent.classList.add("card-content"); | |
const profileImage = document.createElement("img"); | |
profileImage.src = "images/" + itemName + ".png"; | |
profileImage.alt = itemName; | |
profileImage.classList.add("profile-image"); | |
const platformHeading = document.createElement("h2"); | |
platformHeading.textContent = itemName; | |
// Check if the extension is new or updated | |
const versionTag = document.createElement("span"); | |
versionTag.classList.add("version-tag"); | |
if (item.status === "new") { | |
versionTag.textContent = "New"; | |
versionTag.classList.add("new-tag"); | |
platformHeading.appendChild(versionTag); | |
} else if (item.status === "updated") { | |
versionTag.textContent = "Updated"; | |
versionTag.classList.add("updated-tag"); | |
platformHeading.appendChild(versionTag); | |
} | |
cardContent.appendChild(profileImage); | |
cardContent.appendChild(platformHeading); | |
profileCard.appendChild(cardContent); | |
profileCardLink.appendChild(profileCard); | |
featuredCardsContainer.appendChild(profileCardLink); | |
} | |
}); | |
data.files.forEach(item => { | |
const itemName = item.name.split(".")[0]; // Remove file extension | |
const isJsFile = item.name.endsWith(".js"); | |
if (isJsFile) { | |
const profileCardLink = document.createElement("a"); | |
profileCardLink.href = item.download_url; | |
profileCardLink.target = "_blank"; | |
profileCardLink.rel = "noopener noreferrer"; | |
profileCardLink.classList.add("gallery-link"); | |
const profileCard = document.createElement("div"); | |
profileCard.classList.add("profile-card"); | |
const cardContent = document.createElement("div"); | |
cardContent.classList.add("card-content"); | |
const platformHeading = document.createElement("h2"); | |
platformHeading.textContent = itemName; | |
cardContent.appendChild(platformHeading); | |
profileCard.appendChild(cardContent); | |
profileCardLink.appendChild(profileCard); | |
fileCardsContainer.appendChild(profileCardLink); | |
} | |
}); | |
} | |
`; | |
// Replace the script | |
indexHtml = indexHtml.substring(0, scriptStartIndex) + newScript + indexHtml.substring(scriptEndIndex); | |
// Write the updated index.html (as a new file) | |
fs.writeFileSync(outputFile, indexHtml); | |
// Commit the updated previous_versions.json | |
try { | |
const commands = [ | |
["git", "config", "--local", "user.email", "[email protected]"], | |
["git", "config", "--local", "user.name", "GitHub Action"], | |
["git", "add", "cache/previous_versions.json"], | |
["git", "commit", "-m", "\"Update previous_versions.json [skip ci]\""], | |
["git", "push"] | |
]; | |
for (const cmd of commands) { | |
execSync(cmd.join(" "), { stdio: "inherit" }); | |
} | |
console.log("Committed previous_versions.json"); | |
} catch (error) { | |
console.log("No changes to commit or error in committing:", error); | |
} | |
console.log("Successfully compiled extension data into index.html from original.html template"); | |
} else { | |
console.error("Could not find script section to replace in original.html"); | |
process.exit(1); | |
} | |
' | |
- name: Generate Extensions Metadata | |
run: | | |
node -e " | |
const fs = require('fs'); | |
const path = require('path'); | |
const { execSync } = require('child_process'); | |
// Read files from directories | |
const featuredDir = 'featured'; | |
const imagesDir = 'images'; | |
const versionsFile = 'versions.json'; | |
const metadataDir = 'generated-metadata'; | |
// Create metadata directory if it doesn't exist | |
if (!fs.existsSync(metadataDir)) { | |
fs.mkdirSync(metadataDir, { recursive: true }); | |
} | |
// Read versions data | |
const versions = JSON.parse(fs.readFileSync(versionsFile, 'utf8')); | |
// Get featured files data | |
const extensions = fs.readdirSync(featuredDir) | |
.filter(file => file.endsWith('.js')) | |
.map(file => { | |
const filePath = path.join(featuredDir, file); | |
const stats = fs.statSync(filePath); | |
const name = file.split('.')[0]; | |
const imagePath = path.join(imagesDir, name + '.png'); | |
return { | |
slug: name.toLowerCase(), | |
id: name, | |
name: name, | |
description: '', | |
image: 'images/' + name + '.png', | |
by: [{ | |
name: 'Mistium', | |
link: 'https://github.com/Mistium' | |
}] | |
}; | |
}); | |
// Create the metadata object | |
const metadata = { | |
extensions: extensions | |
}; | |
// Write the metadata file | |
fs.writeFileSync(path.join(metadataDir, 'extensions-v0.json'), JSON.stringify(metadata, null, 2)); | |
console.log('Successfully generated extensions metadata file'); | |
// Commit the generated metadata file | |
try { | |
const commands = [ | |
['git', 'config', '--local', 'user.email', '[email protected]'], | |
['git', 'config', '--local', 'user.name', 'GitHub Action'], | |
['git', 'add', path.join(metadataDir, 'extensions-v0.json')], | |
['git', 'commit', '-m', '\"Update extensions metadata\"'], | |
['git', 'push'] | |
]; | |
for (const cmd of commands) { | |
execSync(cmd.join(' '), { stdio: 'inherit' }); | |
} | |
console.log('Committed extensions metadata file'); | |
} catch (error) { | |
console.log('No changes to commit or error in committing:', error); | |
} | |
" | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: '.' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |