Skip to content

Commit

Permalink
feat: support user custom gradient theme
Browse files Browse the repository at this point in the history
  • Loading branch information
shaobeichen committed Oct 29, 2024
1 parent 9773c4c commit 6bec359
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,22 @@
"command": "extension.disable",
"title": "Gradient Theme: Disable Gradient"
}
]
],
"configuration": {
"title": "Gradient Theme",
"properties": {
"gradientTheme.css": {
"type": "array",
"default": [
{
"enable": false,
"css": ""
}
],
"description": "custom css for the gradient theme"
}
}
}
},
"activationEvents": [
"onCommand:extension.enable",
Expand All @@ -91,4 +106,4 @@
"vsce": {
"dependencies": false
}
}
}
18 changes: 16 additions & 2 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,26 @@ function reset() {
}

function install() {
const themeConfig = vscode.workspace.getConfiguration('gradientTheme')
const css = themeConfig ? themeConfig.css : []
const customCssOutHtml = css
.filter((item) => item.enable)
.reduce((prev, cur) => {
return (
prev +
`
<style ${tagAttr}>
${cur.css}
</style>
`
)
}, '')

const distIndexHtmlFile = path.join(__dirname, '../dist/index.html')
const html = getResetContent()
const styleHtml = fs.readFileSync(distIndexHtmlFile, 'utf-8')
const output = html.replace('</html>', '') + styleHtml + '</html>'
const output = html.replace('</html>', '') + customCssOutHtml + styleHtml + '</html>'
fs.writeFileSync(htmlFile, output, 'utf-8')

showReloadMessage(enableMessage)
}

Expand Down

0 comments on commit 6bec359

Please sign in to comment.