Skip to content

Commit

Permalink
Merge pull request #81 from kunai-consulting/pagefind
Browse files Browse the repository at this point in the history
Pagefind
  • Loading branch information
thejackshelton-kunaico authored Jan 8, 2025
2 parents 829ecf4 + 606ca74 commit b8a4fe1
Show file tree
Hide file tree
Showing 109 changed files with 2,726 additions and 413 deletions.
3 changes: 3 additions & 0 deletions apps/docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ lerna-debug.log*
# Yarn
.yarn/*
!.yarn/releases

# Cloudflare
functions/**/*.js
52 changes: 52 additions & 0 deletions apps/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Cloudflare Pages

Cloudflare's [wrangler](https://github.com/cloudflare/wrangler) CLI can be used to preview a production build locally. To start a local server, run:

```
pnpm serve
```

Then visit [http://localhost:8787/](http://localhost:8787/)

### Deployments

[Cloudflare Pages](https://pages.cloudflare.com/) are deployable through their [Git provider integrations](https://developers.cloudflare.com/pages/platform/git-integration/).

If you don't already have an account, then [create a Cloudflare account here](https://dash.cloudflare.com/sign-up/pages). Next go to your dashboard and follow the [Cloudflare Pages deployment guide](https://developers.cloudflare.com/pages/framework-guides/deploy-anything/).

Within the projects "Settings" for "Build and deployments", the "Build command" should be `pnpm build`, and the "Build output directory" should be set to `dist`.

### Function Invocation Routes

Cloudflare Page's [function-invocation-routes config](https://developers.cloudflare.com/pages/platform/functions/routing/#functions-invocation-routes) can be used to include, or exclude, certain paths to be used by the worker functions. Having a `_routes.json` file gives developers more granular control over when your Function is invoked.
This is useful to determine if a page response should be Server-Side Rendered (SSR) or if the response should use a static-site generated (SSG) `index.html` file.

By default, the Cloudflare pages adaptor _does not_ include a `public/_routes.json` config, but rather it is auto-generated from the build by the Cloudflare adaptor. An example of an auto-generate `dist/_routes.json` would be:

```
{
"include": [
"/*"
],
"exclude": [
"/_headers",
"/_redirects",
"/build/*",
"/favicon.ico",
"/manifest.json",
"/service-worker.js",
"/about"
],
"version": 1
}
```

In the above example, it's saying _all_ pages should be SSR'd. However, the root static files such as `/favicon.ico` and any static assets in `/build/*` should be excluded from the Functions, and instead treated as a static file.

In most cases the generated `dist/_routes.json` file is ideal. However, if you need more granular control over each path, you can instead provide you're own `public/_routes.json` file. When the project provides its own `public/_routes.json` file, then the Cloudflare adaptor will not auto-generate the routes config and instead use the committed one within the `public` directory.

## Static Site Generator (Node.js)

```shell
pnpm build.server
```
19 changes: 19 additions & 0 deletions apps/docs/adapters/static/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { staticAdapter } from "@builder.io/qwik-city/adapters/static/vite";
import { extendConfig } from "@builder.io/qwik-city/vite";
import baseConfig from "../../vite.config";

export default extendConfig(baseConfig, () => {
return {
build: {
ssr: true,
rollupOptions: {
input: ["@qwik-city-plan"],
},
},
plugins: [
staticAdapter({
origin: "https://yoursite.qwik.dev",
}),
],
};
});
4 changes: 2 additions & 2 deletions apps/docs/auto-api/auto-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "node:fs";
import { resolve } from "node:path";
import fs from "node:fs";
import type { AnatomyItem, ComponentParts, SubComponents } from "./types";
import { parseComponentAnatomy, parseSingleComponentFromDir } from "./utils";
import { resolve } from "node:path";

export function loopOnAllChildFiles(filePath: string) {
const childComponentMatch = /[\\/](\w[\w-]*)\.tsx$/.exec(filePath);
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/auto-api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ts from "typescript";
import * as fs from "node:fs";
import { resolve } from "node:path";
import fs from "node:fs";

import type {
AnatomyItem,
SubComponents,
Expand Down
16 changes: 11 additions & 5 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
},
"engines-annotation": "Mostly required by sharp which needs a Node-API v9 compatible runtime",
"private": true,
"trustedDependencies": ["sharp"],
"trustedDependencies": [
"sharp"
],
"trustedDependencies-annotation": "Needed for bun to allow running install scripts",
"type": "module",
"scripts": {
"build": "qwik build",
"build": "qwik build && npx pagefind --site dist",
"build.client": "vite build",
"build.preview": "vite build --ssr src/entry.preview.tsx",
"build.server": "vite build -c adapters/static/vite.config.ts",
"build.types": "tsc --incremental --noEmit",
"deploy": "echo 'Run \"npm run qwik add\" to install a server adapter'",
"deploy": "wrangler pages deploy ./dist",
"dev": "vite --mode ssr --host",
"dev.debug": "node --inspect-brk ./node_modules/vite/bin/vite.js --mode ssr --force",
"preview": "qwik build preview && vite preview --open",
"serve": "wrangler pages dev ./dist --compatibility-flags=nodejs_als",
"start": "vite --open --mode ssr",
"qwik": "qwik"
},
Expand All @@ -26,18 +30,20 @@
"@builder.io/qwik-city": "^1.9",
"@kunai-consulting/qwik-components": "workspace:*",
"@kunai-consulting/qwik-hooks": "workspace:*",
"@qwik-ui/headless": "^0.6.1",
"@qwik-ui/headless": "^0.6.4",
"@qwikest/icons": "^0.0.13",
"@types/estree-jsx": "1.0.5",
"@types/node": "20.14.11",
"autoprefixer": "^10.4.20",
"pagefind": "1.2.0",
"postcss": "^8.4.41",
"tailwindcss": "^3.4.10",
"typescript": "5.4.5",
"undici": "*",
"unified": "^11.0.4",
"vite": "^5.4",
"vite-tsconfig-paths": "^4.2.1",
"@qwikest/icons": "^0.0.13"
"wrangler": "^3.0.0"
},
"dependencies": {
"class-variance-authority": "^0.7.0",
Expand Down
9 changes: 9 additions & 0 deletions apps/docs/public/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://developers.cloudflare.com/pages/platform/headers/

/*service-worker.js
Cache-Control: no-store
Content-Type: application/javascript
X-Content-Type-Options: nosniff

/build/*
Cache-Control: public, max-age=31536000, s-maxage=31536000, immutable
1 change: 1 addition & 0 deletions apps/docs/public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# https://developers.cloudflare.com/pages/platform/redirects/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions apps/docs/public/pagefind/pagefind-entry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"1.2.0","languages":{"en-us":{"hash":"en-us_442e12edd512a","wasm":"en-us","page_count":7}}}
Loading

0 comments on commit b8a4fe1

Please sign in to comment.