Skip to content
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
3 changes: 3 additions & 0 deletions site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Latest (/docs/) is a build time copy of the latest version
/docs

# Root index page is conditionally generated if docs is not at the root
/src/pages/index.tsx

# Generated files
.docusaurus
.cache-loader
Expand Down
18 changes: 9 additions & 9 deletions site/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ const config: Config = {
sidebarPath: './sidebars.ts',
// Docs are served at the configured route base path
routeBasePath,
editUrl: ({ docPath }) => {
// Find where docs/ starts in the path and use everything from there
const docsIndex = docPath.indexOf('docs/');
if (docsIndex !== -1) {
const cleanPath = docPath.substring(docsIndex);
// TODO: When implementing versioned docs, this will need to handle version branches
return `https://github.com/HarperDB/documentation/blob/main/${cleanPath}`;
editUrl: ({ versionDocsDirPath, docPath }) => {
// For versioned docs: versionDocsDirPath is like 'versioned_docs/version-4.6'
// For current docs: versionDocsDirPath is 'docs'
if (versionDocsDirPath.startsWith('versioned_docs')) {
// Versioned docs are in site/versioned_docs/version-X.X/
return `https://github.com/HarperDB/documentation/blob/main/site/${versionDocsDirPath}/${docPath}`;
} else {
// Current docs are in the root docs/ directory
return `https://github.com/HarperDB/documentation/blob/main/docs/${docPath}`;
}
// Fallback if docs/ is not found
return `https://github.com/HarperDB/documentation/blob/main/docs/${docPath}`;
},
lastVersion: '4.6',
includeCurrentVersion: false,
Expand Down
7 changes: 4 additions & 3 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "0.0.0",
"private": true,
"scripts": {
"prebuild": "node scripts/prebuild.js",
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"start": "npm run prebuild && docusaurus start",
"build": "npm run prebuild && docusaurus build",
"version": "node scripts/cut-version.js",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"clear": "npm run prebuild -- clean && docusaurus clear",
"serve": "docusaurus serve",
"typecheck": "tsc"
},
Expand Down
70 changes: 70 additions & 0 deletions site/scripts/prebuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env node

/**
* Pre-build script for Docusaurus
* Handles dynamic configuration based on environment variables
*
* Usage:
* node prebuild.js - Setup for build/start
* node prebuild.js clean - Clean generated files
*/

const fs = require('node:fs');
const path = require('node:path');

// Check if running in clean mode
const isCleanMode = process.argv[2] === 'clean';

// Get the route base path from environment variable
const routeBasePath = process.env.DOCUSAURUS_ROUTE_BASE_PATH || '/';

const indexPagePath = path.join(__dirname, '../src/pages/index.tsx');
const pagesDir = path.join(__dirname, '../src/pages');

// Helper function to remove the index page
function removeIndexPage() {
if (fs.existsSync(indexPagePath)) {
fs.unlinkSync(indexPagePath);
console.log('Removed index.tsx');
return true;
}
return false;
}

if (isCleanMode) {
// Clean mode - remove all generated files
console.log('Cleaning generated files...');
removeIndexPage();
process.exit(0);
}

console.log('Running pre-build setup...');
console.log(`Route base path: ${routeBasePath}`);

// Setup index redirect page based on route configuration
if (routeBasePath === '/') {
// If docs are at root, remove the index redirect page
console.log('Docs are at root (/), removing index redirect page, if it exists...');
removeIndexPage();
} else {
// If docs are not at root, ensure the index redirect page exists
console.log(`Docs are at ${routeBasePath}, creating index redirect page...`);

// Create pages directory if it doesn't exist
if (!fs.existsSync(pagesDir)) {
fs.mkdirSync(pagesDir, { recursive: true });
}

// Create the redirect page
const redirectContent = `import React from 'react';
import { Redirect } from '@docusaurus/router';

export default function Home(): JSX.Element {
// Redirect to the docs location
return <Redirect to="${routeBasePath}" />;
}
`;

fs.writeFileSync(indexPagePath, redirectContent);
console.log(`Created index redirect to ${routeBasePath}`);
}
23 changes: 0 additions & 23 deletions site/src/pages/index.module.css

This file was deleted.

12 changes: 0 additions & 12 deletions site/src/pages/index.tsx

This file was deleted.