Skip to content

Commit

Permalink
kicak start some search with algolia (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl authored Nov 8, 2023
1 parent 1646f24 commit 2afd113
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 38 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/gen-algolia-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env -S pkgx deno run --allow-read=. --allow-net

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

interface Package {
project: string
description: string
brief: string
displayName: string
programs: string[]
}

export async function getKettleRemoteMetadata() {
const headers = { Authorization: 'public' }
const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers})
const data = await rsp.json() as (Package & { short_description: string })[]
/// just pick out the fields we want
return data.map(({ project, description, short_description }) => ({ project, description, brief: short_description }))
}

function get_name(yml: any, project: string) {
return get_pkg_name({ project, display_name: yml['display_name'], provides: yml['provides'] })
}


const rv = await getKettleRemoteMetadata()

for (const obj of rv as Package[]) {
const yaml_path = `./projects/${obj.project}/package.yml`
const txt = await Deno.readTextFileSync(yaml_path)
const yml = await yaml.parse(txt) as Record<string, any>

const node = yml['provides']
const provides: string[] = isArray(node) ? node : isString(node) ? [node] : []

obj.displayName = get_name(yaml_path, obj.project)
obj.programs = provides.map(x => x.slice(4))
}

console.log(JSON.stringify(rv, null, 2))

12 changes: 3 additions & 9 deletions .github/scripts/gen-index.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function getKettleRemoteMetadata() {
const headers = { Authorization: 'public' }
const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers})
const foo = await rsp.json() as {project: string, short_description: string}[]
return foo.reduce((acc, {project, short_description}) => {
return foo.reduce((acc, {project, short_description, description}) => {
acc[project] = short_description
return acc
}, {} as Record<string, string>)
Expand Down Expand Up @@ -75,18 +75,12 @@ 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 "../../src/utils/pkg-name.ts";
import get_pkg_name from "./utils/get-name.ts";

async function get_name(path: string, project: string): Promise<string | undefined> {
const txt = await Deno.readTextFileSync(path)
const yml = await parse(txt) as Record<string, any>
if (yml['display-name']) {
return yml['display-name']
} else if (isArray(yml.provides) && yml.provides.length == 1) {
return yml.provides[0].slice(4)
} else {
return get_pkg_name(project)
}
return get_pkg_name({ project, display_name: yml['display_name'], provides: yml['provides'] })
}

import { parse_pkgs_node } from "https://deno.land/x/[email protected]/src/hooks/usePantry.ts"
Expand Down
15 changes: 15 additions & 0 deletions .github/scripts/utils/get-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import get_name_base from '../../../src/utils/pkg-name.ts'
import { isArray, isString } from "https://deno.land/x/[email protected]/src/index.ts";

export default function get_name(opts: {display_name?: string, provides?: (string[] | string), project: string}): string {
const { display_name, provides, project } = opts
if (display_name) {
return display_name
} else if (isArray(provides) && provides?.length == 1) {
return provides[0].slice(4)
} else if (isString(provides)) {
return (provides as string)!.slice(4)
} else {
return get_name_base(project)
}
}
24 changes: 24 additions & 0 deletions .github/workflows/indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,27 @@ jobs:
create-invalidation
--distribution-id E15VQ3SI584CSG
--paths /pkgs /pkgs/ /pkgs/*

algolia:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: pkgxdev/pantry
fetch-depth: 0 # needed to get git metadata for ordering purposes

- uses: actions/checkout@v4
with:
path: utils

- uses: pkgxdev/setup@v2

- run: utils/.github/scripts/gen-algolia-data.ts > algolia.json

# FIXME replace with something that cares about versioning :-/
- uses: wangchucheng/algolia-uploader@master
with:
app_id: UUTLHX01W7
admin_key: ${{ secrets.ALGOLIA_ADMIN_KEY }}
index_name: pkgs
index_file_path: ./algolia.json
Loading

0 comments on commit 2afd113

Please sign in to comment.