From d6796fdddb00efd5975c9919e29b505c87d1c5da Mon Sep 17 00:00:00 2001 From: Nathan Totten Date: Sun, 8 Oct 2023 17:29:27 -0400 Subject: [PATCH] fixed static paths --- docusaurus.config.js | 176 -------------------------------- next.config.mjs | 8 +- src/app/docs/[...slug]/page.tsx | 9 +- src/components/Search.tsx | 32 +++--- src/lib/content.ts | 32 ++---- 5 files changed, 28 insertions(+), 229 deletions(-) delete mode 100644 docusaurus.config.js diff --git a/docusaurus.config.js b/docusaurus.config.js deleted file mode 100644 index e6e503a0..00000000 --- a/docusaurus.config.js +++ /dev/null @@ -1,176 +0,0 @@ -// @ts-check -// Note: type annotations allow type checking and IDEs autocompletion - -const lightCodeTheme = require("prism-react-renderer/themes/github"); -const darkCodeTheme = require("prism-react-renderer/themes/dracula"); - -/** @type {import('@docusaurus/types').Config} */ -const config = { - title: "Zuplo Docs", - tagline: "The programmable API Gateway", - url: "https://zuplo.com", - baseUrl: "/", - trailingSlash: false, - onBrokenLinks: "throw", - onBrokenMarkdownLinks: "throw", - favicon: "https://cdn.zuplo.com/www/favicon.png", - organizationName: "zuplo", // Usually your GitHub org/user name. - projectName: "docs", // Usually your repo name. - markdown: { - mermaid: true, - }, - plugins: [ - "./src/plugins/koala", - "./src/plugins/hubspot", - "@docusaurus/theme-mermaid", - [ - "posthog-docusaurus", - { - apiKey: "phc_xB1aydh7a41MW9TwUtLJjKme4izQiWf9zKbKhpysAiW", - appUrl: "https://app.posthog.com", // optional - enableInDevelopment: false, // optional - }, - ], - ], - presets: [ - [ - "classic", - /** @type {import('@docusaurus/preset-classic').Options} */ - ({ - docs: { - sidebarPath: require.resolve("./sidebars.js"), - editUrl: ({ - version, - versionDocsDirPath, - docPath, - permalink, - locale, - }) => { - if (docPath.startsWith("policies/")) { - const policyId = docPath - .replace("policies/", "") - .replace(".md", ""); - return `https://github.com/zuplo/docs/tree/main/policies/${policyId}`; - } - return `https://github.com/zuplo/docs/tree/main/docs/${docPath}`; - }, - }, - theme: { - customCss: require.resolve("./src/css/custom.css"), - }, - sitemap: { - changefreq: "weekly", - priority: 0.5, - ignorePatterns: ["/docs/conferences/**"], - }, - }), - ], - ], - - themeConfig: - /** @type {import('@docusaurus/preset-classic').ThemeConfig} */ - ({ - image: "https://cdn.zuplo.com/static/social/img-twitter-header.jpg", - algolia: { - // The application ID provided by Algolia - appId: "E7EUGPZYED", - - // Public API key: it is safe to commit it - apiKey: "b2b9d3c7d9be346b7754344b8c3bccdd", - - indexName: "ZUPLO_SITE", - - // Optional: see doc section below - contextualSearch: true, - - // Optional: Specify domains where the navigation should occur through window.location instead on history.push. Useful when our Algolia config crawls multiple documentation sites and we want to navigate with window.location.href to them. - externalUrlRegex: "zuplo\\.com/blog|zuplo\\.com/pricing", - - // Optional: Algolia search parameters - searchParameters: {}, - - //... other Algolia params - }, - navbar: { - logo: { - alt: "Zuplo", - src: "https://cdn.zuplo.com/static/logos/logo.svg", - href: "https://zuplo.com", - target: "_self", - }, - items: [ - { href: "https://zuplo.com", label: "Home", position: "left" }, - { - to: "/docs/intro", - position: "left", - label: "Docs", - }, - { href: "https://zuplo.com/blog", label: "Blog", position: "left" }, - { - href: "https://portal.zuplo.com", - label: "Sign In", - position: "right", - }, - ], - }, - footer: { - style: "dark", - links: [ - { - title: "Company", - items: [ - { - label: "About Us", - href: "https://zuplo.com/about", - }, - { - label: "Pricing", - href: "https://zuplo.com/pricing", - }, - { - label: "Careers", - href: "https://zuplo.com/careers", - }, - ], - }, - { - title: "Community", - items: [ - { - label: "Discord", - href: "https://discord.gg/W36Ddfcd", - }, - { - label: "Twitter", - href: "https://twitter.com/zuplo", - }, - { - label: "LinkedIn", - href: "https://www.linkedin.com/company/75040051/admin/", - }, - ], - }, - { - title: "More", - items: [ - { - label: "Blog", - href: "https://zuplo.com/blog", - }, - { - label: "GitHub", - href: "https://github.com/zuplo", - }, - ], - }, - ], - copyright: `Copyright © ${new Date().getFullYear()} Zuplo, Inc.`, - }, - prism: { - theme: lightCodeTheme, - darkTheme: darkCodeTheme, - }, - }), -}; - -module.exports = config; diff --git a/next.config.mjs b/next.config.mjs index d2e4eb52..aa5b2fc4 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,7 +1,3 @@ -import withMarkdoc from "@markdoc/next.js"; - -import withSearch from "./src/markdoc/search.mjs"; - /** @type {import('next').NextConfig} */ const nextConfig = { pageExtensions: ["js", "jsx", "md", "ts", "tsx"], @@ -15,6 +11,4 @@ const nextConfig = { }, }; -export default withSearch( - withMarkdoc({ schemaPath: "./src/markdoc" })(nextConfig), -); +export default nextConfig; diff --git a/src/app/docs/[...slug]/page.tsx b/src/app/docs/[...slug]/page.tsx index d8754f82..d085bdaf 100644 --- a/src/app/docs/[...slug]/page.tsx +++ b/src/app/docs/[...slug]/page.tsx @@ -14,8 +14,6 @@ export async function generateMetadata({ params: { slug: string[] }; }): Promise { const result = await getContentBySlug({ - dir: "docs", - baseUrlPath: "/docs", slug: params.slug, }); if (!result) { @@ -30,8 +28,6 @@ export async function generateMetadata({ export default async function Page({ params }: { params: { slug: string[] } }) { const result = await getContentBySlug({ - dir: "docs", - baseUrlPath: "/docs", slug: params.slug, }); if (!result) { @@ -48,10 +44,7 @@ export default async function Page({ params }: { params: { slug: string[] } }) { } export async function generateStaticParams() { - const posts = await getAllContent({ - dir: "docs", - baseUrlPath: "/docs", - }); + const posts = await getAllContent(); return posts.map((post) => ({ slug: post.slug, })); diff --git a/src/components/Search.tsx b/src/components/Search.tsx index b6781a48..0cfc2807 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -1,7 +1,6 @@ "use client"; import { NavItem, NavSection, navigation } from "@/lib/navigation"; -import { type Result } from "@/markdoc/search.mjs"; import { createAutocomplete, type AutocompleteApi, @@ -23,6 +22,8 @@ import { } from "react"; import Highlighter from "react-highlight-words"; +type Result = any; + type EmptyObject = Record; type Autocomplete = AutocompleteApi< @@ -86,20 +87,21 @@ function useAutocomplete({ navigate, }, getSources({ query }) { - return import("@/markdoc/search.mjs").then(({ search }) => { - return [ - { - sourceId: "documentation", - getItems() { - return search(query, { limit: 5 }); - }, - getItemUrl({ item }) { - return `/docs/${item.url.replace(".md", "")}`; - }, - onSelect: navigate, - }, - ]; - }); + return []; + // return import("@/markdoc/search.mjs").then(({ search }) => { + // return [ + // { + // sourceId: "documentation", + // getItems() { + // return search(query, { limit: 5 }); + // }, + // getItemUrl({ item }) { + // return `/docs/${item.url.replace(".md", "")}`; + // }, + // onSelect: navigate, + // }, + // ]; + // }); }, }), ); diff --git a/src/lib/content.ts b/src/lib/content.ts index 0853e2db..e942a354 100644 --- a/src/lib/content.ts +++ b/src/lib/content.ts @@ -1,8 +1,8 @@ import { existsSync } from "fs"; import fs from "fs/promises"; +import { glob } from "glob"; import matter from "gray-matter"; import path from "path"; - export interface BaseContent> { source: string; data: Data; @@ -18,18 +18,12 @@ export interface Content> { } export async function getContentBySlug>({ - dir, - baseUrlPath, slug, }: { - dir: string; - baseUrlPath: string; slug: string[]; }): Promise | undefined> { const fileName = `${slug.join("/")}.md`; - console.log(fileName); - const directory = path.join(process.cwd(), dir); - const filepath = path.join(directory, fileName); + const filepath = path.join(process.cwd(), "docs", fileName); if (!existsSync(filepath)) { return undefined; } @@ -41,31 +35,23 @@ export async function getContentBySlug>({ const result: Content = { source: content, data: data as Data, - href: `${baseUrlPath}/${slug}`, + href: `/docs/${slug}`, slug, }; return result; } -export async function getAllContent>({ - dir, - baseUrlPath, - limit, -}: { - dir: string; - baseUrlPath: string; +export async function getAllContent>(options?: { limit?: number; }): Promise[]> { - const directory = path.join(process.cwd(), dir); - const contentFiles = await fs.readdir(directory); - + const contentFiles = await glob(`docs/**/*.md`); const results = await Promise.all( contentFiles .filter((f) => f.endsWith(".md")) .sort() .reverse() .map(async (file) => { - const filepath = path.join(directory, file); + const filepath = path.join(process.cwd(), file); const source = await fs.readFile(filepath); const { data, content } = matter(source); @@ -73,15 +59,15 @@ export async function getAllContent>({ const result: Content = { source: content, data: data as Data, - href: `${baseUrlPath}/${file}`, + href: file.replace(".md", ""), slug: file.replace(".md", "").split("/"), }; return result; }), ); - if (limit) { - return results.splice(0, limit); + if (options?.limit) { + return results.splice(0, options.limit); } return results;