Commit 49c77d8d49
Unsigned
Layout: unified · split
api/src/api.ts −1
| @@ -56,7 +56,6 @@ app.get('/search/:searchTerm', async (c) => { | |||
| 56 | return c.json(mappedResults); | 56 | return c.json(mappedResults); |
| 57 | }); | 57 | }); |
| 58 | 58 | ||
| 59 | |||
| 60 | /* Returns an array of all section IDs within a given category */ | 59 | /* Returns an array of all section IDs within a given category */ |
| 61 | app.get('/:category', async (c) => { | 60 | app.get('/:category', async (c) => { |
| 62 | const { categories } = await fetchAwesomePrivacyData(); | 61 | const { categories } = await fetchAwesomePrivacyData(); |
api/src/utils.ts +6 −5
| @@ -2,13 +2,15 @@ import * as yaml from 'js-yaml'; | |||
| 2 | 2 | ||
| 3 | import type { AwesomePrivacy, Service } from './types'; | 3 | import type { AwesomePrivacy, Service } from './types'; |
| 4 | 4 | ||
| 5 | |||
| 6 | /* Given a category/section/listing title, return it's slug/ID */ | 5 | /* Given a category/section/listing title, return it's slug/ID */ |
| 7 | export const slugify = (title: string): string => title.toLowerCase().replace(/\s+/g, '-'); | 6 | export const slugify = (title: string): string => title.toLowerCase().replace(/\s+/g, '-'); |
| 8 | 7 | ||
| 8 | /* Base path, for fetching static files from GitHub CDN */ | ||
| 9 | const ghCdnRoot = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy'; | ||
| 10 | |||
| 9 | /* Fetches and parses Awesome Privacy source data from GitHub CDN */ | 11 | /* Fetches and parses Awesome Privacy source data from GitHub CDN */ |
| 10 | export const fetchAwesomePrivacyData = async (): Promise<AwesomePrivacy> => { | 12 | export const fetchAwesomePrivacyData = async (): Promise<AwesomePrivacy> => { |
| 11 | const res = await fetch('https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/awesome-privacy.yml'); | 13 | const res = await fetch(`${ghCdnRoot}/main/awesome-privacy.yml`); |
| 12 | const text = await res.text(); | 14 | const text = await res.text(); |
| 13 | return yaml.load(text) as AwesomePrivacy; | 15 | return yaml.load(text) as AwesomePrivacy; |
| 14 | }; | 16 | }; |
| @@ -23,10 +25,9 @@ export const fetchAllServices = async (): Promise<Service[]> => { | |||
| 23 | export const findBySlug = <T extends { name: string }>(collection: T[], slug: string): T | undefined => | 25 | export const findBySlug = <T extends { name: string }>(collection: T[], slug: string): T | undefined => |
| 24 | collection.find(item => slugify(item.name) === slug); | 26 | collection.find(item => slugify(item.name) === slug); |
| 25 | 27 | ||
| 26 | 28 | /* For the homepage root, fetch and render the Swagger docs */ | |
| 27 | export const renderRemoteIndex = async (ctx) => { | 29 | export const renderRemoteIndex = async (ctx) => { |
| 28 | const indexHtmlUrl = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/api/public/index.html'; | 30 | const response = await fetch(`${ghCdnRoot}/main/api/public/index.html`); |
| 29 | const response = await fetch(indexHtmlUrl); | ||
| 30 | if (response.ok) { | 31 | if (response.ok) { |
| 31 | const htmlContent = await response.text(); | 32 | const htmlContent = await response.text(); |
| 32 | return ctx.html(htmlContent); | 33 | return ctx.html(htmlContent); |