mirror of
https://github.com/fmhy/edit.git
synced 2026-01-18 01:41:52 +11:00
feat(transformer): transform Discors links to icons
This commit is contained in:
parent
7d63a3025a
commit
905c88c0d2
2 changed files with 67 additions and 37 deletions
|
|
@ -136,14 +136,14 @@ export function transformer(): Plugin {
|
||||||
!id.includes('posts') &&
|
!id.includes('posts') &&
|
||||||
!id.includes('other')
|
!id.includes('other')
|
||||||
) {
|
) {
|
||||||
const header = getHeader(id)
|
const header = getHeader(_id)
|
||||||
const contents = transform(code)
|
const contents = transform(code)
|
||||||
|
|
||||||
if (_id === 'beginners-guide.md') {
|
if (_id === 'beginners-guide.md') {
|
||||||
const _contents = transformGuide(contents)
|
const _contents = transformGuide(contents)
|
||||||
return header + _contents
|
return header + _contents
|
||||||
}
|
}
|
||||||
return header + contents
|
return header + transformLinks(contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -155,8 +155,7 @@ function getHeader(id: string) {
|
||||||
|
|
||||||
const description = '<p class="text-black dark:text-text-2">'
|
const description = '<p class="text-black dark:text-text-2">'
|
||||||
|
|
||||||
const _id = basename(id)
|
const data = headers[id]
|
||||||
const data = headers[_id]
|
|
||||||
let header = '---\n'
|
let header = '---\n'
|
||||||
header += `title: "${data.title}"\n`
|
header += `title: "${data.title}"\n`
|
||||||
header += `description: ${data.description}\n`
|
header += `description: ${data.description}\n`
|
||||||
|
|
@ -185,15 +184,17 @@ export function transformGuide(text: string): string {
|
||||||
function replaceUnderscore(text: string): string {
|
function replaceUnderscore(text: string): string {
|
||||||
const pattern = /\/#[\w\-]+(?:_[\w]+)*/g
|
const pattern = /\/#[\w\-]+(?:_[\w]+)*/g
|
||||||
const matches = text.match(pattern) || []
|
const matches = text.match(pattern) || []
|
||||||
|
let _text = text
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const replacement = match.replace(/_/g, '-')
|
const replacement = match.replace(/_/g, '-')
|
||||||
text = text.replace(match, replacement)
|
_text = _text.replace(match, replacement)
|
||||||
}
|
}
|
||||||
return text
|
return _text
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transform(text: string): string {
|
export function transform(text: string): string {
|
||||||
let _text = text
|
let _text = text
|
||||||
|
// Transform reddit index links
|
||||||
.replace(
|
.replace(
|
||||||
/\*\*\[◄◄ Back to Wiki Index\]\(https:\/\/www\.reddit\.com\/r\/FREEMEDIAHECKYEAH\/wiki\/index\)\*\*\n/gm,
|
/\*\*\[◄◄ Back to Wiki Index\]\(https:\/\/www\.reddit\.com\/r\/FREEMEDIAHECKYEAH\/wiki\/index\)\*\*\n/gm,
|
||||||
''
|
''
|
||||||
|
|
@ -206,11 +207,13 @@ export function transform(text: string): string {
|
||||||
/\*\*\[Table of Contents\]\(https?:\/\/.*?ibb\.co.*\)\*\* - For mobile users\n/gm,
|
/\*\*\[Table of Contents\]\(https?:\/\/.*?ibb\.co.*\)\*\* - For mobile users\n/gm,
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
|
// Remove extra lines
|
||||||
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\*\*\*\n\n/gm, '')
|
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\*\*\*\n\n/gm, '')
|
||||||
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\*\*\* \n\n/gm, '')
|
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\*\*\* \n\n/gm, '')
|
||||||
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\*\*\*\n\n/gm, '')
|
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\*\*\*\n\n/gm, '')
|
||||||
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\n/gm, '')
|
.replace(/\*\*\*\n\*\*\*\n\*\*\*\n\*\*\*\n\n\n\*\*\*\n\n/gm, '')
|
||||||
.replace(/\*\*\*\n\*\*\*\n\n\n\*\*\*\n\n/gm, '')
|
.replace(/\*\*\*\n\*\*\*\n\n\n\*\*\*\n\n/gm, '')
|
||||||
|
// Transform reddit links
|
||||||
.replace(/https:\/\/www.reddit.com\/r\/FREEMEDIAHECKYEAH\/wiki\/ai/g, '/ai')
|
.replace(/https:\/\/www.reddit.com\/r\/FREEMEDIAHECKYEAH\/wiki\/ai/g, '/ai')
|
||||||
.replace(
|
.replace(
|
||||||
/https:\/\/www.reddit.com\/r\/FREEMEDIAHECKYEAH\/wiki\/adblock-vpn-privacy/g,
|
/https:\/\/www.reddit.com\/r\/FREEMEDIAHECKYEAH\/wiki\/adblock-vpn-privacy/g,
|
||||||
|
|
@ -308,6 +311,7 @@ export function transform(text: string): string {
|
||||||
/https:\/\/github.com\/nbats\/FMHYedit\/blob\/main\/base64.md#/g,
|
/https:\/\/github.com\/nbats\/FMHYedit\/blob\/main\/base64.md#/g,
|
||||||
'/base64/#'
|
'/base64/#'
|
||||||
)
|
)
|
||||||
|
// Remove extra characters
|
||||||
.replace(/\/#wiki_/g, '/#')
|
.replace(/\/#wiki_/g, '/#')
|
||||||
.replace(/#wiki_/g, '/#')
|
.replace(/#wiki_/g, '/#')
|
||||||
.replace(/.25BA_/g, '')
|
.replace(/.25BA_/g, '')
|
||||||
|
|
@ -323,14 +327,17 @@ export function transform(text: string): string {
|
||||||
.replace(/# ►/g, '##')
|
.replace(/# ►/g, '##')
|
||||||
.replace(/## ▷/g, '###')
|
.replace(/## ▷/g, '###')
|
||||||
.replace(/####/g, '###')
|
.replace(/####/g, '###')
|
||||||
|
// Replace emojis
|
||||||
.replace(/⭐/g, ':star:')
|
.replace(/⭐/g, ':star:')
|
||||||
.replace(/🌐/g, ':globe-with-meridians: ')
|
.replace(/🌐/g, ':globe-with-meridians: ')
|
||||||
.replace(/↪ /g, ':repeat-button: ')
|
.replace(/↪/g, ':repeat-button: ')
|
||||||
|
// Replace note/warning/tip
|
||||||
.replace(/^\*\*Note\*\* - (.+)$/gm, ':::tip\n$1\n:::')
|
.replace(/^\*\*Note\*\* - (.+)$/gm, ':::tip\n$1\n:::')
|
||||||
.replace(/^\* \*\*Note\*\* - (.+)$/gm, ':::tip\n$1\n:::')
|
.replace(/^\* \*\*Note\*\* - (.+)$/gm, ':::tip\n$1\n:::')
|
||||||
.replace(/^Note - (.+)$/gm, ':::tip\n$1\n:::')
|
.replace(/^Note - (.+)$/gm, ':::tip\n$1\n:::')
|
||||||
.replace(/^\*\*Warning\*\* - (.+)$/gm, ':::warning\n$1\n:::')
|
.replace(/^\*\*Warning\*\* - (.+)$/gm, ':::warning\n$1\n:::')
|
||||||
.replace(/^\*\s([^*])/gm, '- $1')
|
.replace(/^\*\s([^*])/gm, '- $1')
|
||||||
|
// Replace links
|
||||||
.replace(
|
.replace(
|
||||||
/\/storage\/#encode--decode_urls/g,
|
/\/storage\/#encode--decode_urls/g,
|
||||||
'/storage/#encode--decode-urls'
|
'/storage/#encode--decode-urls'
|
||||||
|
|
@ -348,5 +355,16 @@ export function transform(text: string): string {
|
||||||
/(.+?) site or extension\.\n/gm,
|
/(.+?) site or extension\.\n/gm,
|
||||||
'Click on the texts to copy them decoded.\n'
|
'Click on the texts to copy them decoded.\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return _text
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformLinks(text: string): string {
|
||||||
|
const _text = text
|
||||||
|
// Transform Discord links to icons
|
||||||
|
.replace(
|
||||||
|
/\[Discord\]\(([^\)]*?)\)/gm,
|
||||||
|
'<a target="_blank" href="$1"><div alt="Discord" class="i-carbon:logo-discord" /></a>'
|
||||||
|
)
|
||||||
return _text
|
return _text
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,44 @@
|
||||||
{
|
{
|
||||||
"extends": "./.nitro/types/tsconfig.json"
|
"extends": "./.nitro/types/tsconfig.json",
|
||||||
// "compilerOptions": {
|
"compileroptions": {
|
||||||
// "verbatimModuleSyntax": true,
|
"verbatimmodulesyntax": true,
|
||||||
// "baseUrl": ".",
|
"baseurl": ".",
|
||||||
// "module": "esnext",
|
"module": "esnext",
|
||||||
// "target": "esnext",
|
"target": "esnext",
|
||||||
// "lib": ["DOM", "ESNext"],
|
"lib": [
|
||||||
// "strict": true,
|
"dom",
|
||||||
// "jsx": "preserve",
|
"esnext"
|
||||||
// "esModuleInterop": true,
|
],
|
||||||
// "skipLibCheck": true,
|
"strict": true,
|
||||||
// "moduleResolution": "node",
|
"jsx": "preserve",
|
||||||
// "resolveJsonModule": true,
|
"esmoduleinterop": true,
|
||||||
// "noUnusedLocals": true,
|
"skiplibcheck": true,
|
||||||
// "strictNullChecks": true,
|
"moduleresolution": "node",
|
||||||
// "forceConsistentCasingInFileNames": true,
|
"resolvejsonmodule": true,
|
||||||
// "sourceMap": true,
|
"nounusedlocals": true,
|
||||||
// "isolatedModules": true
|
"strictnullchecks": true,
|
||||||
// },
|
"forceconsistentcasinginfilenames": true,
|
||||||
// "include": [
|
"sourcemap": true,
|
||||||
// "**/*.vue",
|
"isolatedmodules": true
|
||||||
// "**/*.tsx",
|
},
|
||||||
// "**/*.ts",
|
"include": [
|
||||||
// ".vitepress/**/**/*.ts",
|
"**/*.vue",
|
||||||
// ".vitepress/**/**/*.tsx",
|
"**/*.tsx",
|
||||||
// ".vitepress/**/**/*.vue"
|
"**/*.ts",
|
||||||
// ],
|
".vitepress/**/**/*.ts",
|
||||||
// "exclude": ["**/node_modules/**", "dist/**"],
|
".vitepress/**/**/*.tsx",
|
||||||
// "extensions": [".js", ".ts", ".tsx", ".jsx", ".vue"],
|
".vitepress/**/**/*.vue"
|
||||||
// "allowSyntheticDefaultImports": true
|
],
|
||||||
|
"exclude": [
|
||||||
|
"**/node_modules/**",
|
||||||
|
"dist/**"
|
||||||
|
],
|
||||||
|
"extensions": [
|
||||||
|
".js",
|
||||||
|
".ts",
|
||||||
|
".tsx",
|
||||||
|
".jsx",
|
||||||
|
".vue"
|
||||||
|
],
|
||||||
|
"allowSyntheticDefaultImports": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue