-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract label config out of css
- Loading branch information
Showing
7 changed files
with
77 additions
and
6 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,35 @@ | ||
import { PluginOption } from 'vite' | ||
import fs from 'fs' | ||
import { SiteConfiguration } from '../src/site' | ||
|
||
export default function newsListGenerator(): PluginOption { | ||
const virtualModuleId = 'virtual:base.css' | ||
const resolvedVirtualModuleId = '\0' + virtualModuleId | ||
|
||
return { | ||
name: 'base-css-generator', | ||
resolveId(id) { | ||
if (id === virtualModuleId) { | ||
return resolvedVirtualModuleId | ||
} | ||
}, | ||
load(id) { | ||
if (id === resolvedVirtualModuleId) { | ||
const base = fs.readFileSync('./src/assets/base.css', 'utf-8') | ||
return base | ||
.replace( | ||
'/* warning text */', | ||
SiteConfiguration.markdown.container.warningLabel ?? 'WARNING', | ||
) | ||
.replace('/* error text */', SiteConfiguration.markdown.container.errorLabel ?? 'ERROR') | ||
.replace('/* info text */', SiteConfiguration.markdown.container.infoLabel ?? 'INFO') | ||
} | ||
}, | ||
handleHotUpdate({ server, file }) { | ||
if (file.includes('src/assets/base.css')) { | ||
const thisModule = server.moduleGraph.getModuleById(resolvedVirtualModuleId) | ||
if (thisModule) return [thisModule] | ||
} | ||
}, | ||
} | ||
} |
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
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,21 @@ | ||
interface SiteConfiguration { | ||
markdown: { | ||
container: { | ||
warningLabel?: string | ||
errorLabel?: string | ||
infoLabel?: string | ||
expanderLabel?: string | ||
} | ||
} | ||
} | ||
|
||
export const SiteConfiguration: SiteConfiguration = { | ||
markdown: { | ||
container: { | ||
warningLabel: '警告', | ||
errorLabel: '错误', | ||
infoLabel: '信息', | ||
expanderLabel: '更多', | ||
}, | ||
}, | ||
} |
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