Skip to content

Commit

Permalink
fix everything
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchen committed Jun 27, 2024
1 parent 58eb55c commit 8696d45
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 38 deletions.
4 changes: 2 additions & 2 deletions docs/services/EmojiService.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions docs/services/FeatureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ class FeatureService implements IFeatureService {
];
}
async getFeatures(): Promise<Feature[]> {
// 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))
Expand Down
31 changes: 16 additions & 15 deletions docs/services/GithubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -90,20 +90,21 @@ class GithubRepositoryEndPointMethods {
return (await Promise.all(tasks)).flat();
}
}
}
export async function getRepoFileInfo(repo: string, path: string): Promise<RepoFileSystemInfo> {
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) {
Expand Down
11 changes: 6 additions & 5 deletions docs/services/ThemeService.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -39,11 +39,11 @@ class ThemeService implements IThemeService {
return this.innerThemeService.getLoadedThemes().includes(name);
}
async fetchThemeObject(info: RemoteThemeInfo): Promise<TextmateTheme> {
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<string>(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);
Expand All @@ -53,8 +53,9 @@ class ThemeService implements IThemeService {
async initializeRegistration(): Promise<void> {
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.`);
})
);
}
Expand Down

0 comments on commit 8696d45

Please sign in to comment.