-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate a homepage feed of all content types
/cc @tsmitty11
- Loading branch information
Showing
3 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
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)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> { | ||
|
This file contains 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