Skip to content

Add Modules navbar entry #246

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ const config = {
position: "left",
label: "Variables",
},
{
type: "doc",
docId: "FreeSWITCH-Explained/Modules/index",
position: "left",
label: "Modules",
},
{
href: "pathname:///../guides",
label: "SignalWire",
Expand Down
67 changes: 67 additions & 0 deletions scripts/moveModulesFolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
We are moving the Modules folder from docs/FreeSWITCH-Explained/Modules to docs/Modules.
This script exists individually in order to not conflict with current PRs that are being worked on.
It can be run manually after the PRs are merged to move the folder and update the links in the markdown files.
*/
const fs = require('fs');
const path = require('path');

const repoRoot = path.resolve(__dirname, '..');
const docsDir = path.join(repoRoot, 'docs');

function moveModulesFolder() {
const oldPath = path.join(docsDir, 'FreeSWITCH-Explained', 'Modules');
const newPath = path.join(docsDir, 'Modules');
if (fs.existsSync(oldPath)) {
try {
fs.renameSync(oldPath, newPath);
console.log(`Moved folder from ${oldPath} to ${newPath}`);
} catch (err) {
if (err.code === 'EPERM') {
fs.cpSync(oldPath, newPath, { recursive: true });
fs.rmSync(oldPath, { recursive: true, force: true });
console.log(`Copied folder from ${oldPath} to ${newPath} and removed original`);
} else {
throw err;
}
}
} else {
console.log(`Folder not found: ${oldPath}`);
}
}

function updateMarkdownLinks(filePath) {
let content = fs.readFileSync(filePath, 'utf8');
let updated = content;
const relativeFilePath = path.relative(docsDir, filePath);
// If file is within docs/Modules, update ../Installation/ links.
if (relativeFilePath.startsWith('Modules' + path.sep)) {
// Change links like ../Installation/ to ../FreeSWITCH-Explained/Installation/
updated = updated.replace(/(\(\s*\.\.\/)Installation\//g, '$1FreeSWITCH-Explained/Installation/');
} else {
// Update links pointing to ../FreeSWITCH-Explained/Modules/
updated = updated.replace(/(\(\s*\.\.\/)FreeSWITCH-Explained\/Modules\//g, '$1Modules/');
}
if (updated !== content) {
fs.writeFileSync(filePath, updated, 'utf8');
console.log(`Updated links in: ${filePath}`);
}
}

function traverseDir(dirPath) {
fs.readdirSync(dirPath, { withFileTypes: true }).forEach(dirent => {
const fullPath = path.join(dirPath, dirent.name);
if (dirent.isDirectory()) {
traverseDir(fullPath);
} else if (dirent.isFile() && fullPath.endsWith('.mdx')) {
updateMarkdownLinks(fullPath);
}
});
}

function main() {
moveModulesFolder();
traverseDir(docsDir);
}

main();
7 changes: 5 additions & 2 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
// By default, Docusaurus generates a sidebar from the docs folder structure
freeswitchExplainedSidebar: [
{ type: "autogenerated", dirName: "FreeSWITCH-Explained" },
],
variablesSidebar: [
{ type: "autogenerated", dirName: "Channel-Variables-Catalog" },
],
freeswitchExplainedSidebar: [
{ type: "autogenerated", dirName: "FreeSWITCH-Explained" },
modulesSidebar: [
{ type: "autogenerated", dirName: "FreeSWITCH-Explained/Modules" },
],

// But you can create a sidebar manually
Expand Down