From eef96d6775d6e45897e3acf1896a7cba170224d9 Mon Sep 17 00:00:00 2001 From: "@andatoshiki" Date: Sun, 17 Sep 2023 02:07:23 -0700 Subject: [PATCH] chore: remove markdowntransform utility components and rename to utils for clarifying confusion between file namings amonst differnet directory --- scripts/markdownTransform.ts | 59 ------------------------------------ 1 file changed, 59 deletions(-) delete mode 100644 scripts/markdownTransform.ts diff --git a/scripts/markdownTransform.ts b/scripts/markdownTransform.ts deleted file mode 100644 index eb783540..00000000 --- a/scripts/markdownTransform.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { join, resolve } from 'node:path' -import fs from 'fs-extra' -import Git from 'simple-git' -import { $fetch } from 'ohmyfetch' - -export const git = Git() - -export const DOCS_URL = 'https://note.toshiki.dev/' - -export const DIR_ROOT = resolve(__dirname, '..') -export const DIR_SRC = resolve(__dirname, '../docs') - -export function replacer(code: string, value: string, key: string, insert: 'head' | 'tail' | 'none' = 'none') { - const START = `` - const END = `` - const regex = new RegExp(`${START}[\\s\\S]*?${END}`, 'im') - - const target = value ? `${START}\n${value}\n${END}` : `${START}${END}` - - if (!code.match(regex)) { - if (insert === 'none') - return code - else if (insert === 'head') - return `${target}\n\n${code}` - else - return `${code}\n\n${target}` - } - - return code.replace(regex, target) -} - -export function uniq(a: T) { - return Array.from(new Set(a)) -} - -async function fetchContributors(page = 1) { - const additional = ['andatoshiki', 'chenskiro'] - - const collaborators: string[] = [] - const data = await $fetch<{ login: string }[]>(`https://api.github.com/repos/andatoshiki/toshiki-notebook/contributors?per_page=100&page=${page}`, { - method: 'get', - headers: { - 'content-type': 'application/json', - }, - }) || [] - collaborators.push(...data.map(i => i.login)) - if (data.length === 100) - collaborators.push(...(await fetchContributors(page + 1))) - - return Array.from(new Set([ - ...collaborators.filter(collaborator => !['renovate[bot]', 'dependabot[bot]', 'renovate-bot', 'github-actions[bot]'].includes(collaborator)), - ...additional, - ])) -} - -export async function updateContributors() { - const collaborators = await fetchContributors() - await fs.writeFile(join(DIR_SRC, './contributors.json'), `${JSON.stringify(collaborators, null, 2)}\n`, 'utf8') -}