Skip to content

Commit

Permalink
generate a homepage feed of all content types
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Nov 11, 2023
1 parent 7fac821 commit 49406fd
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
75 changes: 75 additions & 0 deletions .github/scripts/gen-feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env -S pkgx deno run -A --unstable

import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"

const { options: { pkgsJson, pantryPath, blogPath, scripthubJson } } = await new Command()
.option("--blog-path <path>", "a", { required: true })
.option("--scripthub-json <path>", "b", { required: true })
.option("--pkgs-json <path>", "c", { required: true })
.option("--pantry-path <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/[email protected]/yaml/mod.ts";
import { isArray } from "https://deno.land/x/[email protected]/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<string, any>
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/[email protected]/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))
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ console.log(JSON.stringify(pkgs, null, 2));

//////////////////////////////////////////////////////
import { parse } from "https://deno.land/[email protected]/yaml/mod.ts";
import { isArray } from "https://deno.land/x/[email protected]/src/index.ts";
import get_pkg_name from "./utils/get-name.ts";

async function get_name(path: string, project: string): Promise<string | undefined> {
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 49406fd

Please sign in to comment.