diff --git a/.github/scripts/gen-feed.ts b/.github/scripts/gen-feed.ts new file mode 100755 index 0000000..660824a --- /dev/null +++ b/.github/scripts/gen-feed.ts @@ -0,0 +1,75 @@ +#!/usr/bin/env -S pkgx deno run -A --unstable + +import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts" + +const { options: { pkgsJson, pantryPath, blogPath, scripthubJson } } = await new Command() + .option("--blog-path ", "a", { required: true }) + .option("--scripthub-json ", "b", { required: true }) + .option("--pkgs-json ", "c", { required: true }) + .option("--pantry-path ", "d", { required: true }) + .parse(Deno.args) + +type Entry = { + type: 'blog' | 'pkg' |'script' | 'highlight' + url: string, + title: string, + time: Date, + image?: string + description?: string +} + +const rv: Entry[] = [] + +import { parse } from "https://deno.land/std@0.204.0/yaml/mod.ts"; +import { isArray } from "https://deno.land/x/is_what@v4.1.15/src/index.ts"; + +for (const pkg of JSON.parse(Deno.readTextFileSync(pkgsJson))) { + const { project, name, description, birthtime } = pkg + const txt = await Deno.readTextFileSync(`${pantryPath}/projects/${project}/package.yml`) + const yml = await parse(txt) as Record + if (isArray(yml.provides)) { + rv.push({ + type: 'pkg', + title: name ?? project, + description, + time: new Date(birthtime), + image: `https://gui.tea.xyz/prod/${project}/512x512.webp`, + url: `https://pkgx.dev/pkgs/${project}/` + }) + } +} + +import { extract } from "https://deno.land/std@0.206.0/front_matter/any.ts"; + +for (const {name, isFile} of Deno.readDirSync(`./blog/content`)) { + if (!isFile || !name.endsWith(".md")) continue + const txt = await Deno.readTextFileSync(`${blogPath}/content/${name}`) + const { date, description, title, featured_image } = await parse(extract(txt).frontMatter) + + const slug = title.replace(/[^a-zA-Z0-9]/g, '-') + + rv.push({ + type: 'blog', + time: new Date(date), + description, + title, + image: `https://blog.pkgx.dev/${featured_image}`, + url: `https://blog.pkgx.dev/${slug}`, + }) +} + +for (const script of JSON.parse(Deno.readTextFileSync(scripthubJson)).scripts) { + const { fullname, description, birthtime, avatar, url } = script + rv.push({ + type: 'script', + time: new Date(birthtime), + description, + title: fullname, + image: avatar, + url + }) +} + +rv.sort((a, b) => b.time.getTime() - a.time.getTime()) + +console.log(JSON.stringify(rv)) diff --git a/.github/scripts/gen-index.json.ts b/.github/scripts/gen-pkgs-index.json.ts similarity index 97% rename from .github/scripts/gen-index.json.ts rename to .github/scripts/gen-pkgs-index.json.ts index ab0d1c3..98f2528 100755 --- a/.github/scripts/gen-index.json.ts +++ b/.github/scripts/gen-pkgs-index.json.ts @@ -74,7 +74,6 @@ console.log(JSON.stringify(pkgs, null, 2)); ////////////////////////////////////////////////////// import { parse } from "https://deno.land/std@0.204.0/yaml/mod.ts"; -import { isArray } from "https://deno.land/x/is_what@v4.1.15/src/index.ts"; import get_pkg_name from "./utils/get-name.ts"; async function get_name(path: string, project: string): Promise { diff --git a/.github/workflows/indexer.yml b/.github/workflows/indexer.yml index e354b2f..939ba8e 100644 --- a/.github/workflows/indexer.yml +++ b/.github/workflows/indexer.yml @@ -44,7 +44,7 @@ jobs: - run: aws s3 sync s3://www.pkgx.dev/pkgs/ ./out - run: aws s3 cp s3://www.pkgx.dev/index.html ./out/index.html - - run: ../.github/scripts/gen-index.json.ts > ../out/index.json + - run: ../.github/scripts/gen-pkgs-index.json.ts > ../out/index.json working-directory: pantry - run: cat ./out/index.html @@ -60,6 +60,49 @@ jobs: --distribution-id E15VQ3SI584CSG --paths /pkgs /pkgs/ /pkgs/* + - uses: actions/upload-artifact@v3 + with: + path: out/index.json + + root-indexer: + needs: indexer + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + with: + path: pkgs-json + + - uses: pkgxdev/setup@v2 + - uses: actions/checkout@v4 + + - uses: actions/checkout@v4 + with: + repo: pkgxdev/pantry + path: pantry + + - run: curl https://pkgxdev.github.io/scripthub/index.json > scripthub.json + + - run: > + .github/scripts/gen-feed.ts + --blog-path ./blog + --pkgs-json ./pkgs-json/index.json + --scripthub-json ./scripthub.json + --pantry-path ./pantry + > index.json + + - uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.WWW_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.WWW_AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-2 + + - run: aws s3 cp index.json s3://www.pkgx.dev/index.json + + - run: aws cloudfront + create-invalidation + --distribution-id E15VQ3SI584CSG + --paths /index.json + algolia: runs-on: ubuntu-latest steps: