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
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,26 @@ jobs:
--title "v$RELEASE_VERSION" \
"${KIND[@]}" \
--notes-file "$RUNNER_TEMP/release/release-notes.md"

# Cloudflare Pages deploys the `site` branch as the live docs, so the docs
# change with the release that publishes their API. A job of its own, so a
# failure can be rerun without publishing again. Forced, because a docs
# fix cherry-picked onto `site` between releases has been merged to `main`
# first, so a release made after it includes it.
docs-site:
needs: publish
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- name: Move the docs site to the release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_COMMIT: ${{ github.sha }}
run: |
if ! gh api -X PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/site" \
-f sha="$RELEASE_COMMIT" -F force=true; then
echo "::error::The package is published, but the docs site wasn't moved. Rerun this job, or run: git push --force origin $RELEASE_COMMIT:refs/heads/site"
exit 1
fi
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ to static files. It's a package in the pnpm workspace and isn't published.
`/llms.txt` and `/llms-full.txt` list the current line's pages. Link
between pages with root-relative paths, which the Markdown turns into
full URLs.
- The live docs deploy from the `site` branch, which the Release workflow
moves to each released commit; `main` and pull requests deploy as
previews. Don't push `site` yourself.
- `pnpm run check` doesn't build the site. After changing `site/`, run
`pnpm run build:site`, which builds the package, then prerenders the site
into `site/dist/client`. `pnpm --dir site run dev` serves it while you
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ All notable changes to `@monarcode/effetch`, newest first.
[llms.txt](https://effetch.pages.dev/llms.txt) and
[llms-full.txt](https://effetch.pages.dev/llms-full.txt) list the pages
for LLMs.
- Releases update the documentation site: the live docs show the newest
release's API, and `main` deploys as a preview.

### Changed

Expand Down
17 changes: 14 additions & 3 deletions site/src/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ export function pageMeta(title: string, description: string) {
export const NOT_FOUND_PATH = "/404";
export const NOT_FOUND_MARK = "effetch-not-found";

/** Set by `vite.config.ts` from the build's environment. */
declare const __SOURCE_REF__: string;
declare const __SITE_URL__: string;

export const gitConfig = {
user: "monarcode",
repo: "effetch",
branch: "main",
/**
* The commit the site was built from, so a page's GitHub link shows the
* source it was built from: on the live site, the release's.
*/
ref: __SOURCE_REF__,
};

/** Where the site is served. Link previews and `llms.txt` need full URLs. */
export const SITE_URL = "https://effetch.pages.dev";
/**
* Where this build is served: the live site, or a preview's own address.
* `llms.txt` and the pages' Markdown need full URLs.
*/
export const SITE_URL = __SITE_URL__;

/** The URL of a page's Markdown, for LLMs and the copy button. */
export function getPageMarkdownUrl(page: { slugs: string[] }) {
Expand Down
2 changes: 1 addition & 1 deletion site/src/routes/docs/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function Content({
<MarkdownCopyButton markdownUrl={markdownUrl} />
<ViewOptionsPopover
markdownUrl={markdownUrl}
githubUrl={`https://github.com/${gitConfig.user}/${gitConfig.repo}/blob/${gitConfig.branch}/site/content/docs/${encodeURI(path)}`}
githubUrl={`https://github.com/${gitConfig.user}/${gitConfig.repo}/blob/${gitConfig.ref}/site/content/docs/${encodeURI(path)}`}
/>
</div>
<DocsBody>
Expand Down
13 changes: 12 additions & 1 deletion site/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ const { version } = JSON.parse(
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
) as { version: string };

// The live site, or, on a Cloudflare Pages preview (`main` and pull
// requests), the preview's own address, so its Markdown links stay on it.
const PRODUCTION = "https://effetch.pages.dev";
const preview =
process.env.CF_PAGES_BRANCH && process.env.CF_PAGES_BRANCH !== "site";
const siteUrl = (preview && process.env.CF_PAGES_URL) || PRODUCTION;

export default defineConfig(({ command }) => ({
define: { __PACKAGE_VERSION__: JSON.stringify(version) },
define: {
__PACKAGE_VERSION__: JSON.stringify(version),
__SOURCE_REF__: JSON.stringify(process.env.CF_PAGES_COMMIT_SHA || "main"),
__SITE_URL__: JSON.stringify(siteUrl),
},
plugins: [
// The pages' MDX options run here, in the build, never in the browser.
fumadocsMdx({
Expand Down
Loading