diff --git a/.eleventy.js b/.eleventy.js index b80a39c48..391636bd5 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,61 +1,65 @@ -const fs = require("fs"); +const fs = require('fs') +const execSync = require('child_process').execSync + +const gitHash = execSync('git rev-parse --short HEAD').toString().trim() // rename macos and remove */any function cleanupPlatforms(platforms) { return platforms - .filter(platform => platform !== "*") - .map(platform => platform === "osx" ? "macos" : platform); + .filter(platform => platform !== '*') + .map(platform => platform === 'osx' ? 'macos' : platform) } // author can be string or array, convert to all arrays function cleanupAuthors(author) { if (typeof author === 'string') { - return [author]; + return [author] } - return author; + return author } function minimalPackage(pkg) { // Create a new array of releases with cleaned platforms const releases = (pkg.releases || []).map(release => ({ ...release, - platforms: cleanupPlatforms(release.platforms) - })); + platforms: cleanupPlatforms(release.platforms), + })) // sort releases by date, newest first // secondary by .sublime_text. strip the leading non-digit from that string first, reverse alphabetical releases.sort((a, b) => { - const dateA = new Date(a.date ?? '1970-01-01 00:00:00'); - const dateB = new Date(b.date ?? '1970-01-01 00:00:00'); + const dateA = new Date(a.date ?? '1970-01-01 00:00:00') + const dateB = new Date(b.date ?? '1970-01-01 00:00:00') if (dateA.getTime() !== dateB.getTime()) { - return dateB - dateA; // Newest first + return dateB - dateA // Newest first } // Secondary: compare .sublime_text, strip leading non-digit, reverse alphabetical - const verA = (a.sublime_text || '').replace(/^[^\d]*/, ''); - const verB = (b.sublime_text || '').replace(/^[^\d]*/, ''); - if (verA > verB) return -1; - if (verA < verB) return 1; - return 0; - }); + const verA = (a.sublime_text || '').replace(/^[^\d]*/, '') + const verB = (b.sublime_text || '').replace(/^[^\d]*/, '') + if (verA > verB) return -1 + if (verA < verB) return 1 + return 0 + }) // Split releases with same sublime build and same platform set. // As we're sorted, just keep the first one we see. - const seen = new Set(); - const dedupedReleases = []; - const otherReleases = []; + const seen = new Set() + const dedupedReleases = [] + const otherReleases = [] for (const release of releases) { - const key = `${release.sublime_text}|${[...release.platforms].sort().join('|')}`; + const key = `${release.sublime_text}|${[...release.platforms].sort().join('|')}` if (!seen.has(key)) { - seen.add(key); - dedupedReleases.push(release); - } else { - otherReleases.push(release); + seen.add(key) + dedupedReleases.push(release) + } + else { + otherReleases.push(release) } } // Remove duplicate platforms - const allPlatforms = releases.flatMap(release => release.platforms); - const uniquePlatforms = Array.from(new Set(allPlatforms)); + const allPlatforms = releases.flatMap(release => release.platforms) + const uniquePlatforms = Array.from(new Set(allPlatforms)) return { name: pkg.name, @@ -64,16 +68,45 @@ function minimalPackage(pkg) { releases: dedupedReleases, otherReleases, labels: pkg.labels, - platforms: uniquePlatforms + platforms: uniquePlatforms, + } +} + +function minimalLib(pkg) { + const allPlatforms = pkg.releases.flatMap((release) => { + if (typeof release.platforms !== 'undefined') { + return release.platforms + } + return [] + }) + const uniquePlatforms = Array.from(new Set(allPlatforms)) + + const homepage = pkg.issues.replace('/issues', '') + let gh_path = '' + if (homepage.startsWith('https://github.com/')) { + gh_path = homepage.replace('https://github.com/', '') + } + + return { + name: pkg.name, + homepage: homepage, + path: gh_path, + author: cleanupAuthors(pkg.author), + description: pkg.description, + releases: pkg.releases, + labels: [], + platforms: uniquePlatforms, } } module.exports = function (eleventyConfig) { - eleventyConfig.addPassthroughCopy("static"); + eleventyConfig.addPassthroughCopy('assets') + eleventyConfig.addPassthroughCopy({ static: 'static_' + gitHash }) - const data = JSON.parse(fs.readFileSync("workspace.json", "utf8")); + const libraries = JSON.parse(fs.readFileSync('libraries.json', 'utf8')) + const workspace = JSON.parse(fs.readFileSync('workspace.json', 'utf8')) // eslint-disable-next-line no-unused-vars - const live_packages = Object.entries(data.packages).map(([id, pkg]) => pkg).filter(pkg => !pkg.removed); + const live_packages = Object.entries(workspace.packages).map(([id, pkg]) => pkg).filter(pkg => !pkg.removed) // if readme is in pkg // transform some links @@ -87,75 +120,85 @@ module.exports = function (eleventyConfig) { // => https://bitbucket.org/JeisonJHA/sublime-delphi-language/src/master/README.md // // and store the under readme_url - eleventyConfig.addCollection("packages", () => { - return live_packages.map(pkg => { - let readme_url = pkg.readme; + eleventyConfig.addCollection('packages', () => { + return live_packages.map((pkg) => { + let readme_url = pkg.readme if (typeof readme_url === 'string') { // GitHub raw to blob readme_url = readme_url.replace( /^https:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)\/(.+)$/, - 'https://github.com/$1/$2/blob/$3/$4' - ); + 'https://github.com/$1/$2/blob/$3/$4', + ) // GitLab raw to blob readme_url = readme_url.replace( /^https:\/\/gitlab\.com\/([^/]+)\/([^/]+)\/-\/raw\/([^/]+)\/(.+)$/, - 'https://gitlab.com/$1/$2/-/blob/$3/$4' - ); + 'https://gitlab.com/$1/$2/-/blob/$3/$4', + ) // Bitbucket raw to src readme_url = readme_url.replace( /^https:\/\/bitbucket\.org\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/(.+)$/, - 'https://bitbucket.org/$1/$2/src/$3/$4' - ); + 'https://bitbucket.org/$1/$2/src/$3/$4', + ) } return { ...pkg, ...minimalPackage(pkg), - ...(readme_url !== pkg.readme ? { readme_url } : {}) - }; - }); - }); + ...(readme_url !== pkg.readme ? { readme_url } : {}), + } + }) + }) - eleventyConfig.addCollection("minimal_packages", () => { + eleventyConfig.addCollection('minimal_packages', () => { return live_packages.map(pkg => ({ description: pkg.description, - ...minimalPackage(pkg) - })).sort((a, b) => (b.stars ?? 0) - (a.stars ?? 0)); - }); + ...minimalPackage(pkg), + })).sort((a, b) => (b.stars ?? 0) - (a.stars ?? 0)) + }) - eleventyConfig.addCollection("updated_packages", () => { + eleventyConfig.addCollection('updated_packages', () => { return live_packages.map(pkg => ({ last_modified: pkg.last_modified, - ...minimalPackage(pkg) + ...minimalPackage(pkg), })).sort((a, b) => { return new Date(b.last_modified ?? '1970-01-01 00:00:00') - new Date(a.last_modified ?? '1970-01-01 00:00:00') - }).slice(0,9); - }); + }).slice(0, 9) + }) - eleventyConfig.addCollection("newest_packages", () => { + eleventyConfig.addCollection('newest_packages', () => { return live_packages.map(pkg => ({ created_at: pkg.created_at, - ...minimalPackage(pkg) + ...minimalPackage(pkg), })).sort((a, b) => { return new Date(b.created_at ?? '1970-01-01 00:00:00') - new Date(a.created_at ?? '1970-01-01 00:00:00') - }).slice(0,9); - }); + }).slice(0, 9) + }) + + eleventyConfig.addCollection('libraries', () => { + return libraries.libraries.map(lib => ({ + ...minimalLib(lib), + })) + }) // simple to date string for some dates without times - eleventyConfig.addFilter("date_format", (date) => { - if (typeof date !== "string" ) return date; - return (new Date(date)).toDateString(); - }); - - eleventyConfig.addFilter("stars_format", (count) => { - const starsFormatter = new Intl.NumberFormat("en", { notation: "compact" }); - return starsFormatter.format(count); + eleventyConfig.addFilter('date_format', (date) => { + if (typeof date !== 'string') return date + return (new Date(date)).toDateString() + }) + + eleventyConfig.addFilter('stars_format', (count) => { + const starsFormatter = new Intl.NumberFormat('en', { notation: 'compact' }) + return starsFormatter.format(count) + }) + + eleventyConfig.addFilter('bust', (path) => { + return path.replace('static/', 'static_' + gitHash + '/') }) return { dir: { - input: ".", - output: "_site", + input: '.', + output: '_site', }, - passthroughFileCopy: true - }; -}; + passthroughFileCopy: true, + } +} diff --git a/.gitignore b/.gitignore index b00004829..2afeca44d 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ _site/* # Database # ###################### workspace.json +libraries.json diff --git a/Makefile b/Makefile index 8420166e7..73eaa0da9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ build: npm install + # workspace from https://github.com/packagecontrol/thecrawl curl -o workspace.json -L "https://github.com/packagecontrol/thecrawl/releases/download/crawler-status/workspace.json" + # libraries repository from https://github.com/packagecontrol/channel + curl -o libraries.json -L "https://raw.githubusercontent.com/packagecontrol/channel/refs/heads/main/repository.json" npx @11ty/eleventy curl -o _site/channel.json -L "https://github.com/packagecontrol/thecrawl/releases/download/the-channel/channel.json" curl -o _site/channel_st3.json -L "https://github.com/packagecontrol/thecrawl/releases/download/the-st3-channel/channel_st3.json" diff --git a/_includes/footer.njk b/_includes/footer.njk index 9a2e9811d..9de4431bd 100644 --- a/_includes/footer.njk +++ b/_includes/footer.njk @@ -1,7 +1,7 @@ {% import "packages/macros.njk" as pack %}