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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ coverage/
*.log
plan.json
next-env.d.ts
# Pagefind search index, generated by the build into the static assets
_pagefind/

# Terraform
.terraform/
Expand Down
21 changes: 21 additions & 0 deletions apps/web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Shu Ding

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Nextra Docs Template

This is a template for creating documentation with [Nextra](https://nextra.site).

[**Live Demo →**](https://nextra-docs-template.vercel.app)

[![](.github/screenshot.png)](https://nextra-docs-template.vercel.app)

## Quick Start

Click the button to clone this repository and deploy it on Vercel:

[![](https://vercel.com/button)](https://vercel.com/new/clone?s=https%3A%2F%2Fgithub.com%2Fshuding%2Fnextra-docs-template&showOptionalTeamCreation=false)

## Local Development

First, run `pnpm i` to install the dependencies.

Then, run `pnpm dev` to start the development server and visit localhost:3000.

## License

This project is licensed under the MIT License.
27 changes: 27 additions & 0 deletions apps/web/app/[[...mdxPath]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { generateStaticParamsFor, importPage } from 'nextra/pages'
import { useMDXComponents as getMDXComponents } from '../../mdx-components'

// Every page under content/ is pre-rendered at build time. A Worker has no
// filesystem at request time, so anything outside the page map is a 404.
export const generateStaticParams = generateStaticParamsFor('mdxPath')
export const dynamicParams = false

type PageProps = Readonly<{ params: Promise<{ mdxPath?: string[] }> }>

export async function generateMetadata(props: PageProps) {
const params = await props.params
const { metadata } = await importPage(params.mdxPath)
return metadata
}

const Wrapper = getMDXComponents().wrapper!

export default async function Page(props: PageProps) {
const params = await props.params
const { default: MDXContent, toc, metadata, sourceCode } = await importPage(params.mdxPath)
return (
<Wrapper toc={toc} metadata={metadata} sourceCode={sourceCode}>
<MDXContent {...props} params={params} />
</Wrapper>
)
}
46 changes: 46 additions & 0 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Metadata } from 'next'
import type { ReactNode } from 'react'
import { Footer, Layout, Navbar } from 'nextra-theme-docs'
import { Head } from 'nextra/components'
import { getPageMap } from 'nextra/page-map'
import 'nextra-theme-docs/style.css'

// Upstream theme.config.tsx, expressed through nextra-theme-docs 4's
// Layout / Navbar / Footer: the logo, the project and chat links, the docs
// repository base and the footer text. The title template is what Nextra 2's
// docs theme used by default.
export const metadata: Metadata = {
title: {
default: 'My Project',
template: '%s – Nextra',
},
description: 'Nextra docs template',
}

const navbar = (
<Navbar
logo={<span>My Project</span>}
projectLink="https://github.com/shuding/nextra-docs-template"
chatLink="https://discord.com"
/>
)

const footer = <Footer>Nextra Docs Template</Footer>

export default async function RootLayout({ children }: Readonly<{ children: ReactNode }>) {
return (
<html lang="en" dir="ltr" suppressHydrationWarning>
<Head />
<body>
<Layout
navbar={navbar}
pageMap={await getPageMap()}
docsRepositoryBase="https://github.com/shuding/nextra-docs-template"
footer={footer}
>
{children}
</Layout>
</body>
</html>
)
}
64 changes: 64 additions & 0 deletions apps/web/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: sourceplane.io/v1
kind: Component
metadata:
name: web
description: The docs site (Nextra 4 on Next.js, on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)
spec:
type: cloudflare-workers-assets-turbo
lifecycle: production
owner: platform
domain: web
path: apps/web
# Its own lane per environment: the Next.js build is the longest job in the
# plan, and a shared lane would wait on it.
lane: isolated
subscribe:
environments:
- name: dev
profile: verify
- name: stage
profile: verify
profileRules:
- profile: deploy
when:
triggerRef: github-push-main
- name: prod
profile: verify
profileRules:
- profile: deploy
when:
triggerRef: github-push-main
parameters:
nodeVersion: "22"
pnpmVersion: "10.12.1"

workspaceDir: ../..
appDir: .

turboFilter: "@app/web"
wranglerConfig: wrangler.jsonc

# @opennextjs/cloudflare emits a Worker entrypoint plus a static-assets
# directory bound via ASSETS — both deploy in one `wrangler deploy`.
# The Pagefind search index (public/_pagefind) ships inside the assets.
workerEntrypoint: .open-next/worker.js
assetsDir: .open-next/assets

# Per-env worker name: nextra-docs-web-{dev,stage,prod}.
workerName: nextra-docs-web
environmentAwareWorkerName: true

# The account's workers.dev subdomain; exported to the smoke step as
# ${WORKERS_DEV_SUBDOMAIN} and used to build ${DEPLOYED_URL}.
workersDevSubdomain: your-workers-subdomain

installCommand: pnpm install --frozen-lockfile
buildCommand: pnpm exec turbo run build --filter=@app/web

# Smoke: the home page renders and carries the site's logo text.
smokeCommand: "html=$(curl -sfL \"${DEPLOYED_URL}/\") && echo \"${html}\" | grep -q 'My Project'"
labels:
team: platform
layer: delivery
surface: web
runtime: cloudflare
16 changes: 16 additions & 0 deletions apps/web/components/counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client'

// Upstream defined this component inline in pages/another.mdx. Nextra 4 renders
// MDX as React Server Components, where hooks are not available, so the same
// code lives here as a client component and the page imports it.
import { useState } from 'react'
import styles from './counters.module.css'

export const Counter = () => {
const [count, setCount] = useState(0);
return (
<div>
<button onClick={() => setCount(count + 1)} className={styles.counter}>Clicked {count} times</button>
</div>
);
};
6 changes: 6 additions & 0 deletions apps/web/components/counters.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.counter {
border: 1px solid #ccc;
border-radius: 5px;
padding: 2px 6px;
margin: 12px 0 0;
}
26 changes: 26 additions & 0 deletions apps/web/components/counters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client'

// Example from https://beta.reactjs.org/learn

import { useState } from 'react'
import styles from './counters.module.css'

function MyButton() {
const [count, setCount] = useState(0)

function handleClick() {
setCount(count + 1)
}

return (
<div>
<button onClick={handleClick} className={styles.counter}>
Clicked {count} times
</button>
</div>
)
}

export default function MyApp() {
return <MyButton />
}
20 changes: 20 additions & 0 deletions apps/web/content/_meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { MetaRecord } from 'nextra'

// Upstream pages/_meta.json, as Nextra 4's _meta module: the sidebar order,
// and the two `type: 'page'` entries that sit in the navbar instead.
const meta: MetaRecord = {
index: 'Introduction',
another: 'Another Page',
advanced: 'Advanced (A Folder)',
about: {
title: 'About',
type: 'page',
},
contact: {
title: 'Contact ↗',
type: 'page',
href: 'https://twitter.com/shuding_',
},
}

export default meta
3 changes: 3 additions & 0 deletions apps/web/content/about.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# About

This is the about page! This page is shown on the navbar.
9 changes: 9 additions & 0 deletions apps/web/content/advanced.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Nextra 4: makes this file the folder's own page (upstream Nextra 2 did this
# implicitly for a file beside a folder of the same name).
asIndexPage: true
---

# Advanced

This is the index page for the Advanced folder!
3 changes: 3 additions & 0 deletions apps/web/content/advanced/satori.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Satori

Satori (悟り) is a Japanese Buddhist term for awakening, "comprehension; understanding".
20 changes: 20 additions & 0 deletions apps/web/content/another.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Another Page

```js filename="demo.js" {3} copy
let a = 1;

console.log(a);
```

## Component

{/* The counter is a client component (MDX renders on the server in Nextra 4) */}
import { Counter } from '../components/counter'

<Counter/>

## External Component

import Counters from '../components/counters'

<Counters />
11 changes: 11 additions & 0 deletions apps/web/content/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Introduction

Welcome to Nextra! This is a basic docs template. You can use it as a starting point for your own project :)

## What is Nextra?

A **simple**, **powerful** and **flexible** site generation framework with everything you love from Next.js.

## Documentation

The documentation is available at [https://nextra.site](https://nextra.site).
2 changes: 2 additions & 0 deletions apps/web/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from "../../tooling/eslint/index.js";
export default config;
9 changes: 9 additions & 0 deletions apps/web/mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useMDXComponents as getDocsMDXComponents } from 'nextra-theme-docs'
import type { MDXComponents } from 'nextra/mdx-components'

const docsComponents = getDocsMDXComponents()

export const useMDXComponents = (components?: MDXComponents): MDXComponents => ({
...docsComponents,
...components,
})
22 changes: 22 additions & 0 deletions apps/web/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import nextra from "nextra";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

// Nextra 4: MDX pages come from content/ through app/[[...mdxPath]]/page.tsx;
// search is Pagefind, indexed by the `build` script after `next build`.
const withNextra = nextra({});

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
// Required by @opennextjs/cloudflare, which bundles `.next/standalone/**`
// into the Worker. Trace from the monorepo root so workspace dependencies
// resolve from the root node_modules.
output: "standalone",
outputFileTracingRoot: path.join(__dirname, "../.."),
typescript: { ignoreBuildErrors: false },
};

export default withNextra(nextConfig);
14 changes: 14 additions & 0 deletions apps/web/open-next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// OpenNext Cloudflare adapter config.
//
// The template is statically generated: every page is pre-rendered at build
// time and nothing revalidates. The static-assets incremental cache serves
// those pre-rendered pages straight from the Worker's static assets (read
// only, no R2/KV/D1 to provision), which is exactly the shape of a content
// site. A template that revalidates (ISR, `revalidateTag`) swaps this for the
// R2 incremental cache plus a tag cache.
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config";
import staticAssetsIncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/static-assets-incremental-cache";

export default defineCloudflareConfig({
incrementalCache: staticAssetsIncrementalCache,
});
Loading
Loading