Skip to content

Commit

Permalink
V3 is aliiiiiiiive
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinometric committed Oct 18, 2024
1 parent 74b1337 commit 22abe8d
Show file tree
Hide file tree
Showing 10 changed files with 1,315 additions and 5,176 deletions.
3 changes: 0 additions & 3 deletions website/babel.config.js

This file was deleted.

6 changes: 4 additions & 2 deletions website/clean-generated-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// the bits that are specific to the generation source we use, and make the docs
// easier to use. In particular, removing the leading `/ushosted` is likely to
// save us loooots of questions.
const replace = require('replace-in-file');
const replaceInFileSync = require('replace-in-file');

console.log(replaceInFileSync);

const options = {
files: 'docs/reference/api/**/*.api.mdx',
Expand All @@ -27,4 +29,4 @@ const options = {
to: ['', '"<your-unleash-url>"', '"path":['],
};

replace(options);
replaceInFileSync(options);
54 changes: 26 additions & 28 deletions website/docusaurus.config.js → website/docusaurus.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { sdks } = require('./remote-content/sdks');
const { docs: edgeAndProxy } = require('./remote-content/edge-proxy');
import type { Config } from '@docusaurus/types';

import { sdks } from './remote-content/sdks';
import { docs as edgeAndProxy } from './remote-content/edge-proxy';
import pluginNpm2Yarn from '@docusaurus/remark-plugin-npm2yarn';

// for a given redirect object, modify it's `from` property such that for every
// path that doesn't start with `/docs/`, a corresponding path that _does_ start
Expand Down Expand Up @@ -38,8 +41,8 @@ const addDocsRoutePrefix = ({ from, ...rest }) => {
from: addDocs(from),
};
};
/** @type {import('@docusaurus/types').DocusaurusConfig} */
module.exports = {

const config: Config = {
title: 'Unleash',
tagline: 'The enterprise ready feature flag service',
url: 'https://docs.getunleash.io',
Expand Down Expand Up @@ -169,20 +172,20 @@ module.exports = {
},
],
},
prism: {
theme: require('prism-react-renderer/themes/oceanicNext'),
additionalLanguages: [
'csharp',
'dart',
'http',
'java',
'kotlin',
'php',
'ruby',
'rust',
'swift',
],
},
// prism: {
// theme: require("prism-react-renderer/themes/oceanicNext"),
// additionalLanguages: [
// "csharp",
// "dart",
// "http",
// "java",
// "kotlin",
// "php",
// "ruby",
// "rust",
// "swift",
// ],
// },
languageTabs: [
{
highlight: 'bash',
Expand Down Expand Up @@ -290,22 +293,15 @@ module.exports = {
'@docusaurus/preset-classic',
{
docs: {
sidebarPath: require.resolve('./sidebars.js'),
// Please change this to your repo.
editUrl:
'https://github.com/Unleash/unleash/edit/main/website/',
routeBasePath: '/',
remarkPlugins: [
[
require('@docusaurus/remark-plugin-npm2yarn'),
{ sync: true },
],
],
docLayoutComponent: '@theme/DocPage',
remarkPlugins: [[pluginNpm2Yarn, { sync: true }]],
docItemComponent: '@theme/ApiItem',
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
customCss: './src/css/custom.css',
},
googleAnalytics: {
trackingID: 'UA-134882379-1',
Expand Down Expand Up @@ -928,5 +924,7 @@ module.exports = {
defer: true,
},
],
clientModules: [require.resolve('./global.js')],
clientModules: ['./global.js'],
};

export default config;
50 changes: 16 additions & 34 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,25 @@
"test": "NODE_ENV=test node --trace-warnings ../node_modules/.bin/jest remote-content"
},
"dependencies": {
"@docusaurus/core": "2.3.1",
"@docusaurus/plugin-client-redirects": "2.3.1",
"@docusaurus/plugin-google-analytics": "2.3.1",
"@docusaurus/preset-classic": "2.3.1",
"@docusaurus/core": "^3.5.2",
"@docusaurus/plugin-client-redirects": "^3.5.2",
"@docusaurus/plugin-google-analytics": "^3.5.2",
"@docusaurus/preset-classic": "^3.5.2",
"@docusaurus/remark-plugin-npm2yarn": "2.3.1",
"@docusaurus/theme-mermaid": "2.3.1",
"@mdx-js/react": "1.6.22",
"@docusaurus/theme-mermaid": "^3.5.2",
"@mdx-js/react": "^3.0.1",
"@svgr/webpack": "8.1.0",
"browserslist": "^4.16.5",
"docusaurus-plugin-openapi-docs": "4.1.0",
"docusaurus-plugin-remote-content": "^3.1.0",
"docusaurus-theme-openapi-docs": "2.0.0-beta.2",
"docusaurus-plugin-openapi-docs": "^4.1.0",
"docusaurus-plugin-remote-content": "^4.0.0",
"docusaurus-theme-openapi-docs": "^4.1.0",
"git-url-parse": "^14.0.0",
"plugin-image-zoom": "flexanalytics/plugin-image-zoom",
"prism-react-renderer": "^2.4.0",
"prism-svelte": "^0.5.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"url-loader": "4.1.1"
},
"resolutions": {
"axios": "^0.28.0",
"async": "^3.2.4",
"trim": "^1.0.0",
"got": "^13.0.0",
"glob-parent": "^6.0.0",
"browserslist": "^4.16.5",
"set-value": "^4.0.1",
"ansi-regex": "^5.0.1",
"nth-check": "^2.0.1",
"minimatch": "^5.0.0",
"decode-uri-component": "^0.4.0",
"qs": "^6.9.7",
"ws": "^8.18.0",
"semver": "^7.5.3",
"joi": "17.13.3"
"react": "^18.3.1",
"react-dom": "^18.3.1",
"replace-in-file": "^8.2.0"
},
"browserslist": {
"production": [
Expand All @@ -70,12 +54,10 @@
},
"devDependencies": {
"@babel/core": "7.25.8",
"@docusaurus/module-type-aliases": "2.3.1",
"@docusaurus/module-type-aliases": "^3.5.2",
"@docusaurus/types": "^3.5.2",
"@tsconfig/docusaurus": "2.0.3",
"babel-loader": "9.1.3",
"enhanced-resolve": "5.17.1",
"react-router": "6.26.2",
"replace-in-file": "7.2.0",
"@types/react": "^18.3.11",
"typescript": "5.4.5"
},
"packageManager": "[email protected]"
Expand Down
6 changes: 3 additions & 3 deletions website/remote-content/edge-proxy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {
import {
enrich,
mapObject,
modifyContent,
getRepoData,
getUrls,
} = require('./shared');
} from './shared';

const DOCS = mapObject(enrich)({
'unleash-proxy': {
Expand Down Expand Up @@ -46,7 +46,7 @@ const modifyContent2 = modifyContent({
getAdditionalAdmonitions: getAdmonitions,
});

module.exports.docs = {
export const docs = {
urls: getUrls(DOCS),
modifyContent: modifyContent2,
};
12 changes: 6 additions & 6 deletions website/remote-content/sdks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const {
import {
enrichAdditional,
modifyContent,
getRepoData,
getUrls,
} = require('./shared');
} from './shared';

// Type definitions
//
Expand Down Expand Up @@ -44,9 +44,9 @@ const serverSideSdks = {
'unleash-client-ruby': {
sidebarName: 'Ruby',
},
'unleash-client-rust': {
sidebarName: 'Rust',
},
// 'unleash-client-rust': {
// sidebarName: 'Rust',
// },
'unleash-client-dotnet': {
sidebarName: '.NET',
slugName: 'dotnet',
Expand Down Expand Up @@ -117,7 +117,7 @@ const modifyContent2 = modifyContent({
getAdditionalAdmonitions: getAdmonitions,
});

module.exports.sdks = {
export const sdks = {
urls: getUrls(SDKS),
modifyContent: modifyContent2,
};
2 changes: 1 addition & 1 deletion website/remote-content/sdks.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { docs } = require('./edge-proxy');
import { docs } from './edge-proxy';

test('Should get all sub pages', () => {
expect(docs.urls).toStrictEqual([
Expand Down
23 changes: 14 additions & 9 deletions website/remote-content/shared.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
import path from 'node:path';

module.exports.mapObject = (fn) => (o) =>
export const mapObject = (fn) => (o) =>
Object.fromEntries(Object.entries(o).map(fn));

module.exports.enrichAdditional =
export const enrichAdditional =
(additionalProperties) =>
([repoName, repoData]) => {
const repoUrl = `https://github.com/Unleash/${repoName}`;
Expand All @@ -17,9 +17,10 @@ module.exports.enrichAdditional =
{ ...repoData, repoUrl, slugName, branch, ...additionalProperties },
];
};
module.exports.enrich = module.exports.enrichAdditional({});

module.exports.getRepoData = (documents) => (filename) => {
export const enrich = enrichAdditional({});

export const getRepoData = (documents) => (filename) => {
const repoName = filename.split('/')[0];

const repoData = documents[repoName];
Expand Down Expand Up @@ -80,7 +81,7 @@ const replaceLinks = ({ content, repo }) => {
.replaceAll(imageSrcLink, replaceImageSrcLink);
};

module.exports.modifyContent =
export const modifyContent =
({
getRepoDataFn,
filePath = () => {},
Expand Down Expand Up @@ -128,11 +129,15 @@ module.exports.modifyContent =
content: `---
title: ${subpage?.sidebarName ?? data.sidebarName}
slug: ${processedSlug}
custom_edit_url: ${data.repoUrl}/edit/${data.branch}/${subpage ? subpageKey : 'README.md'}
custom_edit_url: ${data.repoUrl}/edit/${data.branch}/${
subpage ? subpageKey : 'README.md'
}
---
:::info Generated content
This document was generated from ${subpage ? subpageKey : 'README.md'} in the [${data.sidebarName} GitHub repository](${data.repoUrl}).
This document was generated from ${
subpage ? subpageKey : 'README.md'
} in the [${data.sidebarName} GitHub repository](${data.repoUrl}).
:::
${additionalAdmonitions}
Expand All @@ -152,7 +157,7 @@ This content was generated on <time dateTime="${generationTime.toISOString()}">$
};
};

module.exports.getUrls = (documents) =>
export const getUrls = (documents) =>
Object.entries(documents).flatMap(([repo, { branch, subPages }]) => [
`${repo}/${branch}/README.md`,
...(Object.keys(subPages ?? {}).map(
Expand Down
11 changes: 7 additions & 4 deletions website/sidebars.js → website/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
Create as many sidebars as you want.
*/

// TODO: Add warning to legacy API docs - but generated items
// TODO: Continue to clean URLs & redirects - but wait for SEO results first
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';

module.exports = {
import docsSidebar from './docs/reference/api/unleash/sidebar.ts';

const sidebars: SidebarsConfig = {
academy: [
{
label: 'Unleash Academy',
Expand Down Expand Up @@ -382,7 +383,7 @@ module.exports = {
slug: '/reference/api/unleash',
},
items: [
require('./docs/reference/api/unleash/sidebar.ts'),
docsSidebar,
{
'System API': [
'reference/api/legacy/unleash/internal/prometheus',
Expand Down Expand Up @@ -688,3 +689,5 @@ module.exports = {
},
],
};

export default sidebars;
Loading

0 comments on commit 22abe8d

Please sign in to comment.