diff --git a/docs/services/EmojiService.ts b/docs/services/EmojiService.ts index c737df91..ae2334f7 100644 --- a/docs/services/EmojiService.ts +++ b/docs/services/EmojiService.ts @@ -1,7 +1,7 @@ import fg from 'fast-glob'; import { projectRoot } from '../shared/FileSystem'; import { DocumentIcon } from './DocumentService'; -import { getRepoFileInfo, githubService } from './GithubService'; +import { githubService } from './GithubService'; import { EmojiVariant, IEmojiService } from './IEmojiService'; export abstract class EmojiHandler { @@ -33,7 +33,7 @@ class FluentEmojiHandler extends EmojiHandler { ); if (!match.length) throw new Error(`APNG path of emoji ${emoji} not found. Hex: ${hex}`); const path = match[0].path; - const file = await getRepoFileInfo('bignutty/fluent-emoji', path!); + const file = await githubService.fromRepository('bignutty/fluent-emoji').getFileInfo(path!); if (!file) throw new Error(`file of path: ${path} is ${file}`); const url = file.download_url!; return url; diff --git a/docs/services/FeatureService.ts b/docs/services/FeatureService.ts index aa7a2ba1..cead81b9 100644 --- a/docs/services/FeatureService.ts +++ b/docs/services/FeatureService.ts @@ -23,22 +23,6 @@ class FeatureService implements IFeatureService { ]; } async getFeatures(): Promise { - // const features: Feature[] = []; - // for (const key in documentService.documentInfo) { - // if (Object.prototype.hasOwnProperty.call(documentService.documentInfo, key)) { - // const documentInfo = documentService.documentInfo[key]; - // if ((key as DocumentName) !== 'Articles') - // features.push({ - // title: documentService.tryGetFormulaNameOfDocument(key as DocumentName), - // details: documentInfo.description, - // icon: { src: await emojiService.getIconUrl(documentInfo.icon) }, - // link: documentService.tryGetIndexLinkOfDocument(key as DocumentName), - // linkText: this.linkText, - // }); - // } - // } - - // return features; return await Promise.all( Object.keys(documentService.documentInfo) .filter(key => key !== ('Articles' as DocumentName)) diff --git a/docs/services/GithubService.ts b/docs/services/GithubService.ts index 519cefb0..7c99706f 100644 --- a/docs/services/GithubService.ts +++ b/docs/services/GithubService.ts @@ -29,7 +29,7 @@ class GithubRepositoryEndPointMethods { await octokit.rest.git.getRef({ owner: this.owner, repo: this.repo, - ref: `heads/${branch}}`, + ref: `heads/${branch}`, }) ).data.object.sha; } catch (error) { @@ -90,20 +90,21 @@ class GithubRepositoryEndPointMethods { return (await Promise.all(tasks)).flat(); } } -} -export async function getRepoFileInfo(repo: string, path: string): Promise { - if (/^[\w.]+\/\b[-\w]+\b$/.test(repo)) { - const split = repo.split('/'); - const owner = split[0]; - const _repo = split[1]; - return ( - await octokit.rest.repos.getContent({ - owner: owner, - repo: _repo, - path: path, - }) - ).data as RepoFileSystemInfo; - } else throw new Error(); + async getFileInfo(path: string) { + const repo = `${this.owner}/${this.repo}`; + if (/^[\w.]+\/\b[-\w]+\b$/.test(repo)) { + const split = repo.split('/'); + const owner = split[0]; + const _repo = split[1]; + return ( + await octokit.rest.repos.getContent({ + owner: owner, + repo: _repo, + path: path, + }) + ).data as RepoFileSystemInfo; + } else throw new Error(); + } } export class GithubService { constructor(token: string) { diff --git a/docs/services/ThemeService.ts b/docs/services/ThemeService.ts index b431179b..b0d3063c 100644 --- a/docs/services/ThemeService.ts +++ b/docs/services/ThemeService.ts @@ -1,6 +1,6 @@ import axios from 'axios'; import * as shiki from 'shiki'; -import { getRepoFileInfo, githubService } from './GithubService'; +import { githubService } from './GithubService'; import { IThemeService } from './IThemeService'; const highlighter = await shiki.getSingletonHighlighter(); @@ -39,11 +39,11 @@ class ThemeService implements IThemeService { return this.innerThemeService.getLoadedThemes().includes(name); } async fetchThemeObject(info: RemoteThemeInfo): Promise { - const url = (await getRepoFileInfo(info.repo, info.path)).download_url!; + const url = (await githubService.fromRepository(info.repo).getFileInfo(info.path)) + .download_url!; try { const response = await axios.get(url, { responseType: 'text' }); const theme = (await import('jsonc-parser')).parse(response.data) as TextmateTheme; - console.log(theme.name); return theme; } catch (error) { console.error('Error fetching JSON data:', error); @@ -53,8 +53,9 @@ class ThemeService implements IThemeService { async initializeRegistration(): Promise { await Promise.all( (Object.entries(themeInfos) as [ThemeName, RemoteThemeInfo][]).map(async x => { - const json = await this.fetchThemeObject(x[1]); - await this.register(json); + const theme = await this.fetchThemeObject(x[1]); + await this.register(theme); + console.log(`Textmate theme: \`${x[0]}\` has loaded.`); }) ); }