Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto update sphinx theme css files #291

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ lib/core/MetadataBlog.js

website/build
website/translated_docs
website/yarn.lock
website/node_modules
website/i18n/*
.vscode/settings.json
1 change: 1 addition & 0 deletions website/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(node website/updateSiteConfig.js && git add website/siteConfig.js) || true
11 changes: 8 additions & 3 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
"scripts": {
"examples": "docusaurus-examples",
"start": "docusaurus-start",
"build": "docusaurus-build",
"fix-css": "sed -ibak -e 's/@supports selector(.*11\\.5rem)}}//' ./static/docs/current/_static/sphinx_immaterial_theme.*.css",
"build-site": "docusaurus-build",
"build": "yarn fix-css; yarn build-site",
"publish-gh-pages": "docusaurus-publish",
"write-translations": "docusaurus-write-translations",
"version": "docusaurus-version",
"rename-version": "docusaurus-rename-version"
"rename-version": "docusaurus-rename-version",
"update-site-config": "updateSiteConfig",
"prepare": "cd .. && husky website/.husky"
},
"devDependencies": {
"docusaurus": "^1.7.1"
"docusaurus": "^1.7.1",
"husky": "^9.1.7"
}
}
1 change: 1 addition & 0 deletions website/siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,4 @@ const siteConfig = {
};

module.exports = siteConfig;

69 changes: 69 additions & 0 deletions website/updateSiteConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const fs = require('fs');
const path = require('path');

async function updateSphinxThemeFiles() {
const siteConfigPath = path.join(__dirname, './siteConfig.js');
const staticDocsPath = path.join(__dirname, 'static/docs');

let content = fs.readFileSync(siteConfigPath, 'utf8');
let lines = content.split('\n');

const pattern = /\Wstatic\/sphinx_immaterial_theme\.[a-f0-9]+\.min\.css\W/;
const insertLineIndex = lines.findIndex(line => pattern.test(line));

if (insertLineIndex === -1) {
console.error('Could not find sphinx theme file references in siteConfig.js');
process.exit(1);
}

matchSet = new Set();
lines = lines.filter(line => {
if ( !pattern.test(line) ){
return true;
} else {
matchSet.add(line.trim());
return false;
}
});

const versionFolders = fs.readdirSync(staticDocsPath)
.filter(folder => /^\d+\.\d+(\.\d+)?$/.test(folder));

if (versionFolders.length === 0) {
console.error('No version folders found');
process.exit(1);
}

const allCssFiles = [];
const fileSet = new Set();
for (const version of versionFolders) {
const staticPath = path.join(staticDocsPath, version, '_static');
if (fs.existsSync(staticPath)) {
const files = fs.readdirSync(staticPath)
.sort()
.filter(file => file.startsWith('sphinx_immaterial_theme.') && file.endsWith('.min.css'))
.filter(file => {
if ( fileSet.has(file) ) return false;
fileSet.add(file);
return true;
})
.map(file => ` "static/${file}",`);
allCssFiles.push(...files);
}
}

if (matchSet.size === allCssFiles.length &&
allCssFiles.every(file => matchSet.has(file.trim()))) {
process.exit(1);
}

console.info('Found CSS files:', allCssFiles);
lines.splice(insertLineIndex, 0, ...allCssFiles);

fs.writeFileSync(siteConfigPath, lines.join('\n'));
console.log('Successfully updated sphinx theme file references');
process.exit(0);
}

updateSphinxThemeFiles().catch(console.error);

40 changes: 0 additions & 40 deletions website/yarn-error.log

This file was deleted.

Loading