-
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.
sync: Updates from docusaurus-template
- Loading branch information
1 parent
5a0bd0a
commit 124d0e7
Showing
8 changed files
with
142 additions
and
77 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
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
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 |
---|---|---|
@@ -1,71 +1,86 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { getTextColor } = require("./utils"); | ||
const { | ||
getTextColor, | ||
} = require('./utils'); | ||
const { definePrimaryColors, defineIcons, defineNavbarColors, defineNavbarItems } = require('./utils/cssVariables'); | ||
definePrimaryColors, | ||
defineIcons, | ||
defineNavbarColors, | ||
defineNavbarItems, | ||
} = require("./utils/cssVariables"); | ||
const { defineBackgroundDark } = require("./utils/images"); | ||
|
||
function editCSSDark(cssContent, styles) { | ||
const { mainColor, navbarColor, darkModeMainColor, navbarDarkModeColor, backgroundDarkModeColor } = styles; | ||
function editCSSDark(cssContent, styles, images) { | ||
const { | ||
mainColor, | ||
navbarColor, | ||
darkModeMainColor, | ||
navbarDarkModeColor, | ||
backgroundDarkModeColor, | ||
} = styles; | ||
const navbarFinalColor = navbarColor ? navbarColor : mainColor; | ||
const mainDarkColor = darkModeMainColor ? darkModeMainColor : mainColor; | ||
const navbarDarkColor = navbarDarkModeColor ? navbarDarkModeColor : navbarFinalColor; | ||
const navbarBorderColor = '#9c9c9c'; | ||
const navbarDarkColor = navbarDarkModeColor | ||
? navbarDarkModeColor | ||
: navbarFinalColor; | ||
const navbarBorderColor = "#9c9c9c"; | ||
|
||
const luminance = getTextColor(navbarDarkColor); | ||
const isDark = luminance === '#000000'; | ||
const isDark = luminance === "#000000"; | ||
|
||
const variations = { | ||
...definePrimaryColors(mainDarkColor), | ||
...defineNavbarColors(mainDarkColor, navbarDarkColor, navbarBorderColor), | ||
...defineIcons(isDark), | ||
...defineNavbarItems(mainColor, isDark, luminance), | ||
'--bg-defined-text-color': getTextColor(mainDarkColor), | ||
...(backgroundDarkModeColor && { '--ifm-background-color': `${backgroundDarkModeColor} !important` }), | ||
...defineBackgroundDark(images), | ||
"--bg-defined-text-color": getTextColor(mainDarkColor), | ||
...(backgroundDarkModeColor && { | ||
"--ifm-background-color": `${backgroundDarkModeColor} !important`, | ||
}), | ||
}; | ||
|
||
let updatedCSS = cssContent; | ||
|
||
for (const [variable, value] of Object.entries(variations)) { | ||
const regex = new RegExp(`${variable}:\\s*[^;]+;`, 'g'); | ||
const regex = new RegExp(`${variable}:\\s*[^;]+;`, "g"); | ||
updatedCSS = updatedCSS.replace(regex, `${variable}: ${value};`); | ||
} | ||
|
||
return updatedCSS; | ||
} | ||
|
||
const manageCssDark = () => { | ||
const configFilePath = path.join(__dirname, '../../config.json'); | ||
const cssFilePath = path.join(__dirname, '../../src/css/customDark.css'); | ||
fs.readFile(configFilePath, 'utf8', (err, data) => { | ||
const configFilePath = path.join(__dirname, "../../config.json"); | ||
const cssFilePath = path.join(__dirname, "../../src/css/customDark.css"); | ||
|
||
fs.readFile(configFilePath, "utf8", (err, data) => { | ||
if (err) { | ||
console.error('Error reading the config file:', err); | ||
console.error("Error reading the config file:", err); | ||
return; | ||
} | ||
|
||
const config = JSON.parse(data); | ||
const { styles } = config; | ||
const { styles, images } = config; | ||
|
||
fs.readFile(cssFilePath, 'utf8', (err, data) => { | ||
fs.readFile(cssFilePath, "utf8", (err, data) => { | ||
if (err) { | ||
console.error('Error reading the CSS file:', err); | ||
console.error("Error reading the CSS file:", err); | ||
return; | ||
} | ||
const updatedCSS = editCSSDark(data, styles); | ||
fs.writeFile(cssFilePath, updatedCSS, 'utf8', (err) => { | ||
|
||
const updatedCSS = editCSSDark(data, styles, images); | ||
|
||
fs.writeFile(cssFilePath, updatedCSS, "utf8", (err) => { | ||
if (err) { | ||
console.error('Error writing the CSS file:', err); | ||
console.error("Error writing the CSS file:", err); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
if (require.main === module) { | ||
manageCssDark(); | ||
} | ||
|
||
module.exports = manageCssDark; | ||
module.exports = manageCssDark; |
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,37 @@ | ||
function defineBackground(images) { | ||
if (!images.background) { | ||
return { | ||
"--background-image": "transparent", | ||
}; | ||
} | ||
|
||
const background = images.background.startsWith("/") | ||
? images.background.slice(1) | ||
: images.background; | ||
return { | ||
"--background-image": `url("../../static/${background}")`, | ||
}; | ||
} | ||
|
||
function defineBackgroundDark(images) { | ||
if (images.darkBackground === null) { | ||
return { | ||
"--background-image": "transparent", | ||
}; | ||
} | ||
if (!images.darkBackground) { | ||
return defineBackground(images); | ||
} | ||
|
||
const background = images.darkBackground.startsWith("/") | ||
? images.darkBackground.slice(1) | ||
: images.darkBackground; | ||
return { | ||
"--background-image": `url("../../static/${background}")`, | ||
}; | ||
} | ||
|
||
module.exports = { | ||
defineBackground, | ||
defineBackgroundDark, | ||
}; |