From 75f76a830a4acd20ab4c613e8fe596698880ab7f Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Thu, 1 Jun 2023 00:43:58 +0330 Subject: [PATCH] feat: inject logos collective footer links into theme config --- .../docusaurus.config.js | 65 ------------------ packages/logos-docusaurus-preset/src/index.ts | 5 +- .../src/theme-config/base.ts | 68 ++++++++++++++++++- .../src/theme-config/index.ts | 31 +++++++-- .../src/client/theme/Footer/Layout/index.tsx | 29 ++++++-- 5 files changed, 119 insertions(+), 79 deletions(-) diff --git a/packages/docusaurus-playground/docusaurus.config.js b/packages/docusaurus-playground/docusaurus.config.js index 351aa9d..753270b 100644 --- a/packages/docusaurus-playground/docusaurus.config.js +++ b/packages/docusaurus-playground/docusaurus.config.js @@ -119,71 +119,6 @@ const config = { }, ], }, - { - title: 'Research', - items: [ - { - href: '/', - label: 'VacP2P', - }, - { - href: '/', - label: 'AFAIK', - }, - ], - }, - { - title: 'Infrastructure', - items: [ - { - href: '/', - label: 'Waku', - }, - { - href: '/', - label: 'Nimbus', - }, - { - href: '/', - label: 'Codex', - }, - { - href: '/', - label: 'Nomos', - }, - ], - }, - { - title: 'Creative Studio', - items: [ - { - href: '/', - label: 'Acid.info', - }, - ], - }, - { - title: 'Movement', - items: [ - { - href: '/', - label: 'Logos', - }, - ], - }, - { - title: 'User-facing products', - items: [ - { - href: '/', - label: 'Status', - }, - { - href: '/', - label: 'Keycard', - }, - ], - }, ], }, }), diff --git a/packages/logos-docusaurus-preset/src/index.ts b/packages/logos-docusaurus-preset/src/index.ts index 44adef0..d5f8335 100644 --- a/packages/logos-docusaurus-preset/src/index.ts +++ b/packages/logos-docusaurus-preset/src/index.ts @@ -58,9 +58,8 @@ export default function logosPreset( path.join(__dirname, '../static', options.businessUnit), ] - siteConfig.themeConfig = defaultsDeep( - [{}, context.siteConfig.themeConfig, themeConfigs[options.businessUnit]], - false, + siteConfig.themeConfig = themeConfigs[options.businessUnit]( + context.siteConfig.themeConfig, ) Object.entries(siteConfig).forEach( diff --git a/packages/logos-docusaurus-preset/src/theme-config/base.ts b/packages/logos-docusaurus-preset/src/theme-config/base.ts index 04e8b93..2820898 100644 --- a/packages/logos-docusaurus-preset/src/theme-config/base.ts +++ b/packages/logos-docusaurus-preset/src/theme-config/base.ts @@ -18,7 +18,73 @@ export const baseThemeConfig: ThemeConfig = { }, footer: { logo: {}, - links: [], + links: [ + { + title: 'shared:Research', + items: [ + { + href: 'https://vac.dev', + label: 'VacP2P', + }, + { + href: 'https://afaik.institute', + label: 'AFAIK', + }, + ], + }, + { + title: 'shared:Infrastructure', + items: [ + { + href: 'https://waku.org/', + label: 'Waku', + }, + { + href: 'https://nimbus.team/', + label: 'Nimbus', + }, + { + href: 'https://codex.storage', + label: 'Codex', + }, + { + href: '#', + label: 'Nomos', + }, + ], + }, + { + title: 'shared:Creative Studio', + items: [ + { + href: 'https://acid.info', + label: 'Acid.info', + }, + ], + }, + { + title: 'shared:Movement', + items: [ + { + href: 'https://logos.co', + label: 'Logos', + }, + ], + }, + { + title: 'shared:User-facing products', + items: [ + { + href: 'https://status.im', + label: 'Status', + }, + { + href: 'https://keycard.tech', + label: 'Keycard', + }, + ], + }, + ], copyright: `Logos, ${new Date().getFullYear()}`, }, prism: { diff --git a/packages/logos-docusaurus-preset/src/theme-config/index.ts b/packages/logos-docusaurus-preset/src/theme-config/index.ts index 3afdfe0..64b0e3c 100644 --- a/packages/logos-docusaurus-preset/src/theme-config/index.ts +++ b/packages/logos-docusaurus-preset/src/theme-config/index.ts @@ -1,11 +1,32 @@ -import { ThemeConfig } from '@docusaurus/types' +import { ThemeConfig } from '@docusaurus/preset-classic' import { BusinessUnits } from '../types' +import { defaultsDeep } from '../utils/object.utils' +import baseThemeConfig from './base' import codexThemeConfig from './codex' import logosThemeConfig from './logos' import wakuThemeConfig from './waku' -export const themeConfigs: Record = { - [BusinessUnits.Logos]: logosThemeConfig, - [BusinessUnits.Codex]: codexThemeConfig, - [BusinessUnits.Waku]: wakuThemeConfig, +const merge = + (base: ThemeConfig) => + (config: ThemeConfig): ThemeConfig => { + const merged: ThemeConfig = { + ...(defaultsDeep([{}, config, base], false) as ThemeConfig), + } + + return { + ...merged, + footer: { + ...merged.footer, + links: [ + ...(merged.footer?.links ?? []), + ...(baseThemeConfig.footer?.links ?? []), + ], + }, + } + } + +export const themeConfigs: Record> = { + [BusinessUnits.Logos]: merge(logosThemeConfig), + [BusinessUnits.Codex]: merge(codexThemeConfig), + [BusinessUnits.Waku]: merge(wakuThemeConfig), } diff --git a/packages/logos-docusaurus-theme/src/client/theme/Footer/Layout/index.tsx b/packages/logos-docusaurus-theme/src/client/theme/Footer/Layout/index.tsx index 19d8001..38065e7 100644 --- a/packages/logos-docusaurus-theme/src/client/theme/Footer/Layout/index.tsx +++ b/packages/logos-docusaurus-theme/src/client/theme/Footer/Layout/index.tsx @@ -1,11 +1,30 @@ -import React from 'react' -import clsx from 'clsx' -import styles from './styles.module.scss' import { Button } from '@acid-info/lsd-react' +import { MultiColumnFooter, SimpleFooter } from '@docusaurus/theme-common' +import clsx from 'clsx' +import React from 'react' +import styles from './styles.module.scss' + +const groupLinks = ( + links: MultiColumnFooter['links'] | SimpleFooter['links'], +) => { + const siteLinks: any[] = [] + const sharedLinks: any[] = [] + + for (const link of links) { + if ( + 'title' in link && + typeof link.title === 'string' && + link.title.startsWith('shared:') + ) { + sharedLinks.push({ ...link, title: link.title.slice(7) }) + } else siteLinks.push(link) + } + + return [siteLinks, sharedLinks] +} export default function FooterLayout({ style, links, logo, copyright }) { - const firstRow = [...links.props.links.slice(0, 2)] - const secondRow = [...links.props.links.slice(2)] + const [firstRow, secondRow] = groupLinks(links.props.links) const handleScrollToTop = () => { window.scrollTo({