-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(options, config): add external links configuration and integrate…
… into Options component - Introduced a new TOML configuration file for external links used in the Askman Chrome extension, enhancing maintainability and organization of links. - Updated the Options component to load and display external links dynamically, including documentation, issues, and social media links. - Replaced hardcoded links with dynamic references to the new configuration, improving flexibility and reducing code duplication.
- Loading branch information
Showing
3 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# External Links Configuration | ||
# This file contains all external links used in the Askman Chrome extension | ||
|
||
[docs] | ||
# Documentation links | ||
home = "https://docs.qq.com/aio/DWUxocmZJV05GQXF5?p=PaTh0e2q3XbD8s7W4xJGnb#wXyP39ceAltKZiZ02AZpR0" | ||
issues = "https://github.com/askman-dev/askman-chrome-extension/issues" | ||
discussions = "https://github.com/askman-dev/askman-chrome-extension/discussions" | ||
|
||
[social] | ||
# Social media links | ||
wechat_id = "nob301" | ||
wechat_qr = "https://github.com/askman-dev/askman-chrome-extension/raw/refs/heads/main/src/assets/img/askman-group.png" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import toml from '@iarna/toml'; | ||
|
||
export interface ExternalLinks { | ||
docs: { | ||
home: string; | ||
issues: string; | ||
discussions: string; | ||
}; | ||
social: { | ||
wechat_id: string; | ||
wechat_qr: string; | ||
}; | ||
} | ||
|
||
class ExternalLinksManager { | ||
private static instance: ExternalLinksManager; | ||
private links: ExternalLinks | null = null; | ||
|
||
private constructor() {} | ||
|
||
static getInstance(): ExternalLinksManager { | ||
if (!ExternalLinksManager.instance) { | ||
ExternalLinksManager.instance = new ExternalLinksManager(); | ||
} | ||
return ExternalLinksManager.instance; | ||
} | ||
|
||
private validateLinks(data: unknown): data is ExternalLinks { | ||
if (typeof data !== 'object' || data === null) return false; | ||
|
||
const links = data as Record<string, unknown>; | ||
|
||
return ( | ||
'docs' in links && | ||
typeof links.docs === 'object' && | ||
links.docs !== null && | ||
'home' in links.docs && | ||
'issues' in links.docs && | ||
'discussions' in links.docs && | ||
'social' in links && | ||
typeof links.social === 'object' && | ||
links.social !== null && | ||
'wechat_id' in links.social && | ||
'wechat_qr' in links.social | ||
); | ||
} | ||
|
||
async loadLinks(): Promise<ExternalLinks> { | ||
if (this.links) return this.links; | ||
|
||
try { | ||
const response = await fetch('/assets/conf/external-links.toml'); | ||
const text = await response.text(); | ||
const parsed = toml.parse(text); | ||
|
||
if (this.validateLinks(parsed)) { | ||
this.links = parsed; | ||
return this.links; | ||
} | ||
|
||
throw new Error('Invalid external links configuration format'); | ||
} catch (error) { | ||
console.error('Failed to load external links:', error); | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
export default ExternalLinksManager.getInstance(); |