Skip to content

Commit

Permalink
sync: Updates from docusaurus-template
Browse files Browse the repository at this point in the history
  • Loading branch information
writedocs-integration committed Jan 8, 2025
1 parent 5a0bd0a commit 124d0e7
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/components/writedocsComponentsFolder/Cards/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
display: flex;
flex-direction: column;
gap: 5px;
justify-content: center;
justify-content: flex-start;
min-height: 67px;
padding: 16px;
transition: all 0.3s ease;
Expand Down
2 changes: 2 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
--black: #000;
--doc-sidebar-width: 256px !important;

--background-image: transparent;

/* WRITEDOCS VARIABLES */
--primary-color: var(--ifm-color-primary);
--primary-color-light: var(--ifm-color-primary-light);
Expand Down
2 changes: 2 additions & 0 deletions src/css/customDark.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ For readability concerns, you should choose a lighter palette in dark mode.
--ifm-color-primary-lightest: #ffffff;
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);

--background-image: transparent;

--font-main-color: var(--white);

--navbar-color: #000621;
Expand Down
8 changes: 8 additions & 0 deletions src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ html {
scroll-margin-top: var(--scroll-top-margin) !important;
}

#__docusaurus {
background-image: var(--background-image);
background-size: contain;
/* background-position: fixed; */
background-repeat: no-repeat;
flex-shrink: 0;
}

.hide_home_btn {
display: none !important;
}
Expand Down
20 changes: 10 additions & 10 deletions src/integrations/DocsBot/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ const DocsBot = () => {
let integrationAppId = null;
let integration = null;

if (configurations.integrations?.docsbot?.intercom) {
if (configurations.integrations?.askAi?.intercom) {
integration = "Intercom";
IntegrationComponent = IntercomIntegration;
integrationAppId = configurations.integrations.docsbot.intercom;
} else if (configurations.integrations?.docsbot?.zendesk) {
integrationAppId = configurations.integrations.askAi.intercom;
} else if (configurations.integrations?.askAi?.zendesk) {
integration = "Zendesk";
IntegrationComponent = ZendeskIntegration;
integrationAppId = configurations.integrations.docsbot.zendesk;
} else if (configurations.integrations?.docsbot?.hubspot) {
integrationAppId = configurations.integrations.askAi.zendesk;
} else if (configurations.integrations?.askAi?.hubspot) {
integration = "HubSpot";
IntegrationComponent = HubspotIntegration;
integrationAppId = configurations.integrations.docsbot.hubspot;
} else if (configurations.integrations?.docsbot?.freshdesk) {
integrationAppId = configurations.integrations.askAi.hubspot;
} else if (configurations.integrations?.askAi?.freshdesk) {
integration = "Freshdesk";
IntegrationComponent = FreshdeskIntegration;
integrationAppId = configurations.integrations.docsbot.freshdesk;
} else if (configurations.integrations?.docsbot?.helpscout) {
integrationAppId = configurations.integrations.askAi.freshdesk;
} else if (configurations.integrations?.askAi?.helpscout) {
integration = "Help Scout";
IntegrationComponent = HelpScoutIntegration;
integrationAppId = configurations.integrations.docsbot.helpscout;
integrationAppId = configurations.integrations.askAi.helpscout;
}

useEffect(() => {
Expand Down
73 changes: 44 additions & 29 deletions writedocs/styles/darkmode.config.js
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;
75 changes: 38 additions & 37 deletions writedocs/styles/lightmode.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
const fs = require('fs');
const path = require('path');
const {
adjustLightness,
} = require('./utils/color');
const fs = require("fs");
const path = require("path");
const { adjustLightness } = require("./utils/color");
const { getTextColor } = require("./utils");
const {
getTextColor,
} = require('./utils');
const { definePrimaryColors, defineNavbarColors,
defineIcons, defineNavbarItems } = require('./utils/cssVariables');
const { defineSidebar } = require('./utils/sidebarSizes');
definePrimaryColors,
defineNavbarColors,
defineIcons,
defineNavbarItems,
} = require("./utils/cssVariables");
const { defineSidebar } = require("./utils/sidebarSizes");
const { defineBackground } = require("./utils/images");

function defineFixedValues(mainColor) {
return {
'--fixed-main-color': mainColor,
'--fixed-main-hover-color': adjustLightness(mainColor, -0.2),
}
"--fixed-main-color": mainColor,
"--fixed-main-hover-color": adjustLightness(mainColor, -0.2),
};
}

function editCSS(cssContent, config) {
const { styles, navbar, homepage } = config;
const { styles, navbar, homepage, images } = config;
const { mainColor, navbarColor, pagination, logoSize } = styles;
const navbarFinalColor = navbarColor ? navbarColor : mainColor;
const searchbarBorderColor = '#dadde1';
const searchbarBorderColor = "#dadde1";

const luminance = getTextColor(navbarFinalColor);
const isDark = luminance === '#000000';
const isDark = luminance === "#000000";

const variations = {
...definePrimaryColors(mainColor),
Expand All @@ -33,54 +34,54 @@ function editCSS(cssContent, config) {
...defineNavbarItems(mainColor, isDark, luminance, logoSize),
...defineSidebar(navbar, homepage, logoSize),
...defineFixedValues(mainColor),
'--fixed-main-hover-color': adjustLightness(mainColor, -0.2),
'--pagination-display': pagination ? "flex" : "none",
'--searchbar-border-color': searchbarBorderColor,
'--bg-defined-text-color': getTextColor(mainColor),
...defineBackground(images),
"--fixed-main-hover-color": adjustLightness(mainColor, -0.2),
"--pagination-display": pagination ? "flex" : "none",
"--searchbar-border-color": searchbarBorderColor,
"--bg-defined-text-color": getTextColor(mainColor),
};

let updatedCSS = cssContent;

for (const [variable, value] of Object.entries(variations)) {
const regex = new RegExp(`${variable}:\\s*(url\\(.*?\\)|[^;]+);`, 'g');
const regex = new RegExp(`${variable}:\\s*(url\\(.*?\\)|[^;]+);`, "g");
updatedCSS = updatedCSS.replace(regex, `${variable}: ${value};`);
}


return updatedCSS;
}

const manageCss = () => {
const configFilePath = path.join(__dirname, '../../config.json');
const cssFilePath = path.join(__dirname, '../../src/css/custom.css');
fs.readFile(configFilePath, 'utf8', (err, data) => {
const configFilePath = path.join(__dirname, "../../config.json");
const cssFilePath = path.join(__dirname, "../../src/css/custom.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);

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 = editCSS(data, config);
fs.writeFile(cssFilePath, updatedCSS, 'utf8', (err) => {

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) {
manageCss();
}

module.exports = manageCss;
module.exports = manageCss;
37 changes: 37 additions & 0 deletions writedocs/styles/utils/images.js
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,
};

0 comments on commit 124d0e7

Please sign in to comment.