Compare commits
259 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e98d97a271 | ||
![]() |
c33f96e572 | ||
![]() |
0b348a0532 | ||
![]() |
59d4b4eddd | ||
![]() |
adf442036b | ||
![]() |
dc2c4dca08 | ||
![]() |
6ba9c7c02a | ||
![]() |
8d5b13ee03 | ||
![]() |
4d07ac93b4 | ||
![]() |
32d3fc0ce8 | ||
![]() |
00e860d8e6 | ||
![]() |
2acdec323f | ||
![]() |
9e58857746 | ||
![]() |
4bd714b7be | ||
![]() |
78e13bcb40 | ||
![]() |
7d49dff074 | ||
![]() |
cdebd05dc9 | ||
![]() |
2a9290b3df | ||
![]() |
771c05ff18 | ||
![]() |
6dd772bf00 | ||
![]() |
c238dd16d9 | ||
![]() |
b34d521293 | ||
![]() |
bfd72347cf | ||
![]() |
091cc1b05e | ||
![]() |
e9b60c7285 | ||
![]() |
b1a920e5c0 | ||
![]() |
61770d3e50 | ||
![]() |
9db66d500e | ||
![]() |
ee8c1dc968 | ||
![]() |
bb24cd13c7 | ||
![]() |
d61fb266c7 | ||
![]() |
685c06ce2e | ||
![]() |
3ae89a1d16 | ||
![]() |
4d6e7ccba9 | ||
![]() |
f334e78ed6 | ||
![]() |
c5304b35c0 | ||
![]() |
99f353968e | ||
![]() |
ec4700d522 | ||
![]() |
d6f69e830c | ||
![]() |
9ee6fe15fd | ||
![]() |
a21f588c48 | ||
![]() |
2119025513 | ||
![]() |
f70e562432 | ||
![]() |
9ff6c7a3f5 | ||
![]() |
7ca9dd9a70 | ||
![]() |
b397dae951 | ||
![]() |
23b691f38c | ||
![]() |
c18e6cd5bb | ||
![]() |
fe2e16d937 | ||
![]() |
722b4321db | ||
![]() |
9d8d238912 | ||
![]() |
141f053b0d | ||
![]() |
3027eced6c | ||
![]() |
aaa5c8e8e4 | ||
![]() |
4e74d11b1a | ||
![]() |
457b77dd48 | ||
![]() |
3ce6aa49bf | ||
![]() |
9316ddf2f5 | ||
![]() |
fbca56f278 | ||
![]() |
eccad3da5d | ||
![]() |
bcde2abcb2 | ||
![]() |
25979ab216 | ||
![]() |
9818e1ad57 | ||
![]() |
771110a72a | ||
![]() |
dc6a9f3b12 | ||
![]() |
c0b73ddaa4 | ||
![]() |
e86544064c | ||
![]() |
a737207981 | ||
![]() |
a72b1a4224 | ||
![]() |
fbb4523853 | ||
![]() |
da1b6b37fe | ||
![]() |
e26658f4ed | ||
![]() |
b579950ae5 | ||
![]() |
0babbdf780 | ||
![]() |
1efe2e20a4 | ||
![]() |
5928d82a56 | ||
![]() |
696403d3fa | ||
![]() |
2c30abe457 | ||
![]() |
80c3196fee | ||
![]() |
d9159e0ac9 | ||
![]() |
c005fe4408 | ||
![]() |
580c1bd608 | ||
![]() |
270a5dc14a | ||
![]() |
bfa938cc62 | ||
![]() |
e3c50caf13 | ||
![]() |
ca08ec1ae7 | ||
![]() |
2718ab9019 | ||
![]() |
87b803790c | ||
![]() |
e59181c3aa | ||
![]() |
b00198b888 | ||
![]() |
9e3e711646 | ||
![]() |
a8001e9554 | ||
![]() |
dd940a007c | ||
![]() |
a71e17919b | ||
![]() |
aca0c330e7 | ||
![]() |
dcaf806190 | ||
![]() |
23df17233d | ||
![]() |
8d33608808 | ||
![]() |
d618a4e3f3 | ||
![]() |
9c8fec06d2 | ||
![]() |
1cd8e7f0d5 | ||
![]() |
5480269d38 | ||
![]() |
a201105442 | ||
![]() |
cc9704becc | ||
![]() |
6d195fd40a | ||
![]() |
2213424195 | ||
![]() |
5b13ff2199 | ||
![]() |
5a39719898 | ||
![]() |
3c8ccde624 | ||
![]() |
c97fd7089a | ||
![]() |
2acfa0fa23 | ||
![]() |
f6f417a505 | ||
![]() |
a3b6201365 | ||
![]() |
a1162b978a | ||
![]() |
c6f10b44f6 | ||
![]() |
b050162f82 | ||
![]() |
6d350500f1 | ||
![]() |
9b47279fe6 | ||
![]() |
4901472aa8 | ||
![]() |
28fe9b2095 | ||
![]() |
9a0d919a3b | ||
![]() |
598741a571 | ||
![]() |
29c533a265 | ||
![]() |
1a02642469 | ||
![]() |
5794405974 | ||
![]() |
59d5a0ed3a | ||
![]() |
dd6bd498db | ||
![]() |
04423d4931 | ||
![]() |
be846e6a5f | ||
![]() |
32ec711767 | ||
![]() |
91189dfd2f | ||
![]() |
fbc45548f7 | ||
![]() |
7be47742a6 | ||
![]() |
4e4930ef9c | ||
![]() |
01943ff5a0 | ||
![]() |
8cf3e3001f | ||
![]() |
992ac00f7c | ||
![]() |
09f8670db7 | ||
![]() |
7e828252bb | ||
![]() |
c90dbacab0 | ||
![]() |
b7a945e034 | ||
![]() |
dc3323b574 | ||
![]() |
c98ef7e89f | ||
![]() |
2e6a675edd | ||
![]() |
e3162f7a7e | ||
![]() |
9466c145b1 | ||
![]() |
a934397961 | ||
![]() |
b2752e7262 | ||
![]() |
d9e36e60d1 | ||
![]() |
46adb35966 | ||
![]() |
e1c9eabef4 | ||
![]() |
d88e43010a | ||
![]() |
ef72f1bf70 | ||
![]() |
7d4bed64a9 | ||
![]() |
99011cb1b0 | ||
![]() |
c91cf97f99 | ||
![]() |
05e6f05a50 | ||
![]() |
7533d504dc | ||
![]() |
69a0ddf733 | ||
![]() |
a582505daf | ||
![]() |
965f9e123c | ||
![]() |
ff9e60a7fc | ||
![]() |
367bb0e6ce | ||
![]() |
8141cb1587 | ||
![]() |
5ccc2dcbba | ||
![]() |
11c98f5600 | ||
![]() |
5a5ef670fe | ||
![]() |
285c0e9768 | ||
![]() |
adb326c933 | ||
![]() |
0c4281eb53 | ||
![]() |
7ac94e1d84 | ||
![]() |
e1d754ef79 | ||
![]() |
a727b57e46 | ||
![]() |
1a4cfa606f | ||
![]() |
410001b942 | ||
![]() |
f24a147276 | ||
![]() |
137d55eb1b | ||
![]() |
9188939b1f | ||
![]() |
92676d746e | ||
![]() |
1893196939 | ||
![]() |
1ab9c91df1 | ||
![]() |
0ad9111388 | ||
![]() |
cbeef5541f | ||
![]() |
0f04f1262c | ||
![]() |
31e0b7c6f8 | ||
![]() |
a6b2967df8 | ||
![]() |
f84a6554f6 | ||
![]() |
1d5b6f58d8 | ||
![]() |
74f8c13598 | ||
![]() |
56ba2f4fa7 | ||
![]() |
314a88d5c6 | ||
![]() |
a53772bbd1 | ||
![]() |
1915a198d9 | ||
![]() |
1d2dc167f4 | ||
![]() |
3ef2a24f4b | ||
![]() |
d98a3a088a | ||
![]() |
ad52d09567 | ||
![]() |
9f701e5045 | ||
![]() |
67e1beea70 | ||
![]() |
3aa11357aa | ||
![]() |
b3a02909ba | ||
![]() |
1dc208356a | ||
![]() |
3d0ba32070 | ||
![]() |
c5d97db000 | ||
![]() |
0d1f15d37c | ||
![]() |
11c23a137a | ||
![]() |
8a95c865c8 | ||
![]() |
fe4b039b60 | ||
![]() |
497d51973a | ||
![]() |
66d7dd8677 | ||
![]() |
313cef60ee | ||
![]() |
af14ca7c4f | ||
![]() |
e06f681ce7 | ||
![]() |
62906eebd3 | ||
![]() |
9cd072bfc3 | ||
![]() |
319b4497bc | ||
![]() |
b0c079f24a | ||
![]() |
1b122a1da0 | ||
![]() |
b8c46ba81a | ||
![]() |
1416f62a47 | ||
![]() |
8889ab63eb | ||
![]() |
5eec1e98e6 | ||
![]() |
a7a0dcad22 | ||
![]() |
921f45cf70 | ||
![]() |
90c187587f | ||
![]() |
08e20a7006 | ||
![]() |
9e32016508 | ||
![]() |
8a050c0be0 | ||
![]() |
0aacd8ed2e | ||
![]() |
7d7e334976 | ||
![]() |
9cefcd0dd1 | ||
![]() |
4aaeb768d8 | ||
![]() |
743ef712d5 | ||
![]() |
9a6e4e2f80 | ||
![]() |
14cb50de9b | ||
![]() |
dad0ae4e3f | ||
![]() |
9c060f3cf2 | ||
![]() |
16a9caa555 | ||
![]() |
b1c60b8833 | ||
![]() |
50a78bafa5 | ||
![]() |
6ea359e55e | ||
![]() |
cd3bb25626 | ||
![]() |
eb9bbd1666 | ||
![]() |
c36551310d | ||
![]() |
6215dd5565 | ||
![]() |
c89c76b40a | ||
![]() |
a145e320d0 | ||
![]() |
082cbb74c3 | ||
![]() |
93b2481261 | ||
![]() |
d2414b3903 | ||
![]() |
01fc26d2c0 | ||
![]() |
84a9be65ce | ||
![]() |
6715079a89 | ||
![]() |
d613a3d2f2 | ||
![]() |
9b75faafea | ||
![]() |
5a26b582ed | ||
![]() |
4e2aea8a5a | ||
![]() |
40f039983c | ||
![]() |
3b988aec61 |
19
.github/dependabot.yml
vendored
@ -1,11 +1,20 @@
|
|||||||
# To get started with Dependabot version updates, you'll need to specify which
|
|
||||||
# package ecosystems to update and where the package manifests are located.
|
|
||||||
# Please see the documentation for all configuration options:
|
|
||||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
||||||
|
|
||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "npm"
|
- package-ecosystem: "npm"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
|
groups:
|
||||||
|
production-dependencies:
|
||||||
|
applies-to: "version-updates"
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
groups:
|
||||||
|
ci-dependencies:
|
||||||
|
applies-to: "version-updates"
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
|
43
.github/workflows/build-preview.yaml
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
name: Build Preview Deployment
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-preview:
|
||||||
|
if: ${{ github.repository == 'jackyzha0/quartz' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Build Preview
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
|
||||||
|
- name: Check types and style
|
||||||
|
run: npm run check
|
||||||
|
|
||||||
|
- name: Build Quartz
|
||||||
|
run: npx quartz build -d docs -v
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: preview-build
|
||||||
|
path: public
|
2
.github/workflows/ci.yaml
vendored
@ -45,7 +45,7 @@ jobs:
|
|||||||
run: npm test
|
run: npm test
|
||||||
|
|
||||||
- name: Ensure Quartz builds, check bundle info
|
- name: Ensure Quartz builds, check bundle info
|
||||||
run: npx quartz build --bundleInfo
|
run: npx quartz build --bundleInfo -d docs
|
||||||
|
|
||||||
publish-tag:
|
publish-tag:
|
||||||
if: ${{ github.repository == 'jackyzha0/quartz' && github.ref == 'refs/heads/v4' }}
|
if: ${{ github.repository == 'jackyzha0/quartz' && github.ref == 'refs/heads/v4' }}
|
||||||
|
37
.github/workflows/deploy-preview.yaml
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
name: Upload Preview Deployment
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Build Preview Deployment"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
deployments: write
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy-preview:
|
||||||
|
if: ${{ github.repository == 'jackyzha0/quartz' && github.event.workflow_run.conclusion == 'success' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Deploy Preview to Cloudflare Pages
|
||||||
|
steps:
|
||||||
|
- name: Download build artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
id: preview-build-artifact
|
||||||
|
with:
|
||||||
|
name: preview-build
|
||||||
|
path: build
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run-id: ${{ github.event.workflow_run.id }}
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: AdrianGonz97/refined-cf-pages-action@v1
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
projectName: quartz
|
||||||
|
deploymentName: Branch Preview
|
||||||
|
directory: ${{ steps.preview-build-artifact.outputs.download-path }}
|
88
.github/workflows/docker-build-push.yaml
vendored
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
name: Docker build & push image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [v4]
|
||||||
|
tags: ["v*"]
|
||||||
|
pull_request:
|
||||||
|
branches: [v4]
|
||||||
|
paths:
|
||||||
|
- .github/workflows/docker-build-push.yaml
|
||||||
|
- quartz/**
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: ${{ github.repository == 'jackyzha0/quartz' }} # Comment this out if you want to publish your own images on a fork!
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set lowercase repository owner environment variable
|
||||||
|
run: |
|
||||||
|
echo "OWNER_LOWERCASE=${OWNER,,}" >> ${GITHUB_ENV}
|
||||||
|
env:
|
||||||
|
OWNER: "${{ github.repository_owner }}"
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
- name: Inject slug/short variables
|
||||||
|
uses: rlespinasse/github-slug-action@v5.1.0
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
install: true
|
||||||
|
driver-opts: |
|
||||||
|
image=moby/buildkit:master
|
||||||
|
network=host
|
||||||
|
- name: Install cosign
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: sigstore/cosign-installer@v3.8.2
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata tags and labels on PRs
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
id: meta-pr
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ghcr.io/${{ env.OWNER_LOWERCASE }}/quartz
|
||||||
|
tags: |
|
||||||
|
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/quartz"
|
||||||
|
- name: Extract metadata tags and labels for main, release or tag
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
flavor: |
|
||||||
|
latest=auto
|
||||||
|
images: ghcr.io/${{ env.OWNER_LOWERCASE }}/quartz
|
||||||
|
tags: |
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}.{{patch}}
|
||||||
|
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
|
||||||
|
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}
|
||||||
|
labels: |
|
||||||
|
maintainer=${{ github.repository_owner }}
|
||||||
|
org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/quartz"
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
id: build-and-push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
build-args: |
|
||||||
|
GIT_SHA=${{ env.GITHUB_SHA }}
|
||||||
|
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags || steps.meta-pr.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels || steps.meta-pr.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha
|
@ -1,10 +1,10 @@
|
|||||||
FROM node:20-slim as builder
|
FROM node:22-slim AS builder
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
COPY package-lock.json* .
|
COPY package-lock.json* .
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
FROM node:20-slim
|
FROM node:22-slim
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY --from=builder /usr/src/app/ /usr/src/app/
|
COPY --from=builder /usr/src/app/ /usr/src/app/
|
||||||
COPY . .
|
COPY . .
|
||||||
|
@ -161,6 +161,18 @@ document.addEventListener("nav", () => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also add the equivalent of a `beforeunload` event for [[SPA Routing]] via the `prenav` event.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
document.addEventListener("prenav", () => {
|
||||||
|
// executed after an SPA navigation is triggered but
|
||||||
|
// before the page is replaced
|
||||||
|
// one usage pattern is to store things in sessionStorage
|
||||||
|
// in the prenav and then conditionally load then in the consequent
|
||||||
|
// nav
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
It is best practice to track any event handlers via `window.addCleanup` to prevent memory leaks.
|
It is best practice to track any event handlers via `window.addCleanup` to prevent memory leaks.
|
||||||
This will get called on page navigation.
|
This will get called on page navigation.
|
||||||
|
|
||||||
|
@ -25,10 +25,11 @@ The following sections will go into detail for what methods can be implemented f
|
|||||||
- `BuildCtx` is defined in `quartz/ctx.ts`. It consists of
|
- `BuildCtx` is defined in `quartz/ctx.ts`. It consists of
|
||||||
- `argv`: The command line arguments passed to the Quartz [[build]] command
|
- `argv`: The command line arguments passed to the Quartz [[build]] command
|
||||||
- `cfg`: The full Quartz [[configuration]]
|
- `cfg`: The full Quartz [[configuration]]
|
||||||
- `allSlugs`: a list of all the valid content slugs (see [[paths]] for more information on what a `ServerSlug` is)
|
- `allSlugs`: a list of all the valid content slugs (see [[paths]] for more information on what a slug is)
|
||||||
- `StaticResources` is defined in `quartz/resources.tsx`. It consists of
|
- `StaticResources` is defined in `quartz/resources.tsx`. It consists of
|
||||||
- `css`: a list of URLs for stylesheets that should be loaded
|
- `css`: a list of CSS style definitions that should be loaded. A CSS style is described with the `CSSResource` type which is also defined in `quartz/resources.tsx`. It accepts either a source URL or the inline content of the stylesheet.
|
||||||
- `js`: a list of scripts that should be loaded. A script is described with the `JSResource` type which is also defined in `quartz/resources.tsx`. It allows you to define a load time (either before or after the DOM has been loaded), whether it should be a module, and either the source URL or the inline content of the script.
|
- `js`: a list of scripts that should be loaded. A script is described with the `JSResource` type which is also defined in `quartz/resources.tsx`. It allows you to define a load time (either before or after the DOM has been loaded), whether it should be a module, and either the source URL or the inline content of the script.
|
||||||
|
- `additionalHead`: a list of JSX elements or functions that return JSX elements to be added to the `<head>` tag of the page. Functions receive the page's data as an argument and can conditionally render elements.
|
||||||
|
|
||||||
## Transformers
|
## Transformers
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ Transformers **map** over content, taking a Markdown file and outputting modifie
|
|||||||
```ts
|
```ts
|
||||||
export type QuartzTransformerPluginInstance = {
|
export type QuartzTransformerPluginInstance = {
|
||||||
name: string
|
name: string
|
||||||
textTransform?: (ctx: BuildCtx, src: string | Buffer) => string | Buffer
|
textTransform?: (ctx: BuildCtx, src: string) => string
|
||||||
markdownPlugins?: (ctx: BuildCtx) => PluggableList
|
markdownPlugins?: (ctx: BuildCtx) => PluggableList
|
||||||
htmlPlugins?: (ctx: BuildCtx) => PluggableList
|
htmlPlugins?: (ctx: BuildCtx) => PluggableList
|
||||||
externalResources?: (ctx: BuildCtx) => Partial<StaticResources>
|
externalResources?: (ctx: BuildCtx) => Partial<StaticResources>
|
||||||
@ -85,8 +86,10 @@ export const Latex: QuartzTransformerPlugin<Options> = (opts?: Options) => {
|
|||||||
if (engine === "katex") {
|
if (engine === "katex") {
|
||||||
return {
|
return {
|
||||||
css: [
|
css: [
|
||||||
// base css
|
{
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css",
|
// base css
|
||||||
|
content: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
js: [
|
js: [
|
||||||
{
|
{
|
||||||
@ -97,8 +100,6 @@ export const Latex: QuartzTransformerPlugin<Options> = (opts?: Options) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -220,12 +221,26 @@ export type QuartzEmitterPlugin<Options extends OptionType = undefined> = (
|
|||||||
|
|
||||||
export type QuartzEmitterPluginInstance = {
|
export type QuartzEmitterPluginInstance = {
|
||||||
name: string
|
name: string
|
||||||
emit(ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources): Promise<FilePath[]>
|
emit(
|
||||||
|
ctx: BuildCtx,
|
||||||
|
content: ProcessedContent[],
|
||||||
|
resources: StaticResources,
|
||||||
|
): Promise<FilePath[]> | AsyncGenerator<FilePath>
|
||||||
|
partialEmit?(
|
||||||
|
ctx: BuildCtx,
|
||||||
|
content: ProcessedContent[],
|
||||||
|
resources: StaticResources,
|
||||||
|
changeEvents: ChangeEvent[],
|
||||||
|
): Promise<FilePath[]> | AsyncGenerator<FilePath> | null
|
||||||
getQuartzComponents(ctx: BuildCtx): QuartzComponent[]
|
getQuartzComponents(ctx: BuildCtx): QuartzComponent[]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
An emitter plugin must define a `name` field, an `emit` function, and a `getQuartzComponents` function. `emit` is responsible for looking at all the parsed and filtered content and then appropriately creating files and returning a list of paths to files the plugin created.
|
An emitter plugin must define a `name` field, an `emit` function, and a `getQuartzComponents` function. It can optionally implement a `partialEmit` function for incremental builds.
|
||||||
|
|
||||||
|
- `emit` is responsible for looking at all the parsed and filtered content and then appropriately creating files and returning a list of paths to files the plugin created.
|
||||||
|
- `partialEmit` is an optional function that enables incremental builds. It receives information about which files have changed (`changeEvents`) and can selectively rebuild only the necessary files. This is useful for optimizing build times in development mode. If `partialEmit` is undefined, it will default to the `emit` function.
|
||||||
|
- `getQuartzComponents` declares which Quartz components the emitter uses to construct its pages.
|
||||||
|
|
||||||
Creating new files can be done via regular Node [fs module](https://nodejs.org/api/fs.html) (i.e. `fs.cp` or `fs.writeFile`) or via the `write` function in `quartz/plugins/emitters/helpers.ts` if you are creating files that contain text. `write` has the following signature:
|
Creating new files can be done via regular Node [fs module](https://nodejs.org/api/fs.html) (i.e. `fs.cp` or `fs.writeFile`) or via the `write` function in `quartz/plugins/emitters/helpers.ts` if you are creating files that contain text. `write` has the following signature:
|
||||||
|
|
||||||
@ -234,7 +249,7 @@ export type WriteOptions = (data: {
|
|||||||
// the build context
|
// the build context
|
||||||
ctx: BuildCtx
|
ctx: BuildCtx
|
||||||
// the name of the file to emit (not including the file extension)
|
// the name of the file to emit (not including the file extension)
|
||||||
slug: ServerSlug
|
slug: FullSlug
|
||||||
// the file extension
|
// the file extension
|
||||||
ext: `.${string}` | ""
|
ext: `.${string}` | ""
|
||||||
// the file content to add
|
// the file content to add
|
||||||
@ -272,7 +287,7 @@ export const ContentPage: QuartzEmitterPlugin = () => {
|
|||||||
const allFiles = content.map((c) => c[1].data)
|
const allFiles = content.map((c) => c[1].data)
|
||||||
for (const [tree, file] of content) {
|
for (const [tree, file] of content) {
|
||||||
const slug = canonicalizeServer(file.data.slug!)
|
const slug = canonicalizeServer(file.data.slug!)
|
||||||
const externalResources = pageResources(slug, resources)
|
const externalResources = pageResources(slug, file.data, resources)
|
||||||
const componentData: QuartzComponentProps = {
|
const componentData: QuartzComponentProps = {
|
||||||
fileData: file.data,
|
fileData: file.data,
|
||||||
externalResources,
|
externalResources,
|
||||||
|
@ -35,6 +35,8 @@ Some common frontmatter fields that are natively supported by Quartz:
|
|||||||
- `draft`: Whether to publish the page or not. This is one way to make [[private pages|pages private]] in Quartz.
|
- `draft`: Whether to publish the page or not. This is one way to make [[private pages|pages private]] in Quartz.
|
||||||
- `date`: A string representing the day the note was published. Normally uses `YYYY-MM-DD` format.
|
- `date`: A string representing the day the note was published. Normally uses `YYYY-MM-DD` format.
|
||||||
|
|
||||||
|
See [[Frontmatter]] for a complete list of frontmatter.
|
||||||
|
|
||||||
## Syncing your Content
|
## Syncing your Content
|
||||||
|
|
||||||
When your Quartz is at a point you're happy with, you can save your changes to GitHub.
|
When your Quartz is at a point you're happy with, you can save your changes to GitHub.
|
||||||
|
@ -21,3 +21,7 @@ This will start a local web server to run your Quartz on your computer. Open a w
|
|||||||
> - `--serve`: run a local hot-reloading server to preview your Quartz
|
> - `--serve`: run a local hot-reloading server to preview your Quartz
|
||||||
> - `--port`: what port to run the local preview server on
|
> - `--port`: what port to run the local preview server on
|
||||||
> - `--concurrency`: how many threads to use to parse notes
|
> - `--concurrency`: how many threads to use to parse notes
|
||||||
|
|
||||||
|
> [!warning] Not to be used for production
|
||||||
|
> Serve mode is intended for local previews only.
|
||||||
|
> For production workloads, see the page on [[hosting]].
|
||||||
|
@ -21,6 +21,7 @@ const config: QuartzConfig = {
|
|||||||
This part of the configuration concerns anything that can affect the whole site. The following is a list breaking down all the things you can configure:
|
This part of the configuration concerns anything that can affect the whole site. The following is a list breaking down all the things you can configure:
|
||||||
|
|
||||||
- `pageTitle`: title of the site. This is also used when generating the [[RSS Feed]] for your site.
|
- `pageTitle`: title of the site. This is also used when generating the [[RSS Feed]] for your site.
|
||||||
|
- `pageTitleSuffix`: a string added to the end of the page title. This only applies to the browser tab title, not the title shown at the top of the page.
|
||||||
- `enableSPA`: whether to enable [[SPA Routing]] on your site.
|
- `enableSPA`: whether to enable [[SPA Routing]] on your site.
|
||||||
- `enablePopovers`: whether to enable [[popover previews]] on your site.
|
- `enablePopovers`: whether to enable [[popover previews]] on your site.
|
||||||
- `analytics`: what to use for analytics on your site. Values can be
|
- `analytics`: what to use for analytics on your site. Values can be
|
||||||
@ -32,6 +33,7 @@ This part of the configuration concerns anything that can affect the whole site.
|
|||||||
- `{ provider: 'posthog', apiKey: '<your-posthog-project-apiKey>', host: '<your-posthog-host>' }`: use [Posthog](https://posthog.com/);
|
- `{ provider: 'posthog', apiKey: '<your-posthog-project-apiKey>', host: '<your-posthog-host>' }`: use [Posthog](https://posthog.com/);
|
||||||
- `{ provider: 'tinylytics', siteId: '<your-site-id>' }`: use [Tinylytics](https://tinylytics.app/);
|
- `{ provider: 'tinylytics', siteId: '<your-site-id>' }`: use [Tinylytics](https://tinylytics.app/);
|
||||||
- `{ provider: 'cabin' }` or `{ provider: 'cabin', host: 'https://cabin.example.com' }` (custom domain): use [Cabin](https://withcabin.com);
|
- `{ provider: 'cabin' }` or `{ provider: 'cabin', host: 'https://cabin.example.com' }` (custom domain): use [Cabin](https://withcabin.com);
|
||||||
|
- `{provider: 'clarity', projectId: '<your-clarity-id-code' }`: use [Microsoft clarity](https://clarity.microsoft.com/). The project id can be found on top of the overview page.
|
||||||
- `locale`: used for [[i18n]] and date formatting
|
- `locale`: used for [[i18n]] and date formatting
|
||||||
- `baseUrl`: this is used for sitemaps and RSS feeds that require an absolute URL to know where the canonical 'home' of your site lives. This is normally the deployed URL of your site (e.g. `quartz.jzhao.xyz` for this site). Do not include the protocol (i.e. `https://`) or any leading or trailing slashes.
|
- `baseUrl`: this is used for sitemaps and RSS feeds that require an absolute URL to know where the canonical 'home' of your site lives. This is normally the deployed URL of your site (e.g. `quartz.jzhao.xyz` for this site). Do not include the protocol (i.e. `https://`) or any leading or trailing slashes.
|
||||||
- This should also include the subpath if you are [[hosting]] on GitHub pages without a custom domain. For example, if my repository is `jackyzha0/quartz`, GitHub pages would deploy to `https://jackyzha0.github.io/quartz` and the `baseUrl` would be `jackyzha0.github.io/quartz`.
|
- This should also include the subpath if you are [[hosting]] on GitHub pages without a custom domain. For example, if my repository is `jackyzha0/quartz`, GitHub pages would deploy to `https://jackyzha0.github.io/quartz` and the `baseUrl` would be `jackyzha0.github.io/quartz`.
|
||||||
@ -39,11 +41,12 @@ This part of the configuration concerns anything that can affect the whole site.
|
|||||||
- `ignorePatterns`: a list of [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns that Quartz should ignore and not search through when looking for files inside the `content` folder. See [[private pages]] for more details.
|
- `ignorePatterns`: a list of [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) patterns that Quartz should ignore and not search through when looking for files inside the `content` folder. See [[private pages]] for more details.
|
||||||
- `defaultDateType`: whether to use created, modified, or published as the default date to display on pages and page listings.
|
- `defaultDateType`: whether to use created, modified, or published as the default date to display on pages and page listings.
|
||||||
- `theme`: configure how the site looks.
|
- `theme`: configure how the site looks.
|
||||||
- `cdnCaching`: If `true` (default), use Google CDN to cache the fonts. This will generally will be faster. Disable (`false`) this if you want Quartz to download the fonts to be self-contained.
|
- `cdnCaching`: if `true` (default), use Google CDN to cache the fonts. This will generally be faster. Disable (`false`) this if you want Quartz to download the fonts to be self-contained.
|
||||||
- `typography`: what fonts to use. Any font available on [Google Fonts](https://fonts.google.com/) works here.
|
- `typography`: what fonts to use. Any font available on [Google Fonts](https://fonts.google.com/) works here.
|
||||||
- `header`: Font to use for headers
|
- `title`: font for the title of the site (optional, same as `header` by default)
|
||||||
- `code`: Font for inline and block quotes.
|
- `header`: font to use for headers
|
||||||
- `body`: Font for everything
|
- `code`: font for inline and block quotes
|
||||||
|
- `body`: font for everything
|
||||||
- `colors`: controls the theming of the site.
|
- `colors`: controls the theming of the site.
|
||||||
- `light`: page background
|
- `light`: page background
|
||||||
- `lightgray`: borders
|
- `lightgray`: borders
|
||||||
@ -101,8 +104,30 @@ transformers: [
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
Some plugins are included by default in the[ `quartz.config.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz.config.ts), but there are more available.
|
Some plugins are included by default in the [`quartz.config.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz.config.ts), but there are more available.
|
||||||
|
|
||||||
You can see a list of all plugins and their configuration options [[tags/plugin|here]].
|
You can see a list of all plugins and their configuration options [[tags/plugin|here]].
|
||||||
|
|
||||||
If you'd like to make your own plugins, see the [[making plugins|making custom plugins]] guide.
|
If you'd like to make your own plugins, see the [[making plugins|making custom plugins]] guide.
|
||||||
|
|
||||||
|
## Fonts
|
||||||
|
|
||||||
|
Fonts can be specified as a `string` or a `FontSpecification`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// string
|
||||||
|
typography: {
|
||||||
|
header: "Schibsted Grotesk",
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
// FontSpecification
|
||||||
|
typography: {
|
||||||
|
header: {
|
||||||
|
name: "Schibsted Grotesk",
|
||||||
|
weights: [400, 700],
|
||||||
|
includeItalic: true,
|
||||||
|
},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
31
docs/features/Citations.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
title: Citations
|
||||||
|
tags:
|
||||||
|
- feature/transformer
|
||||||
|
---
|
||||||
|
|
||||||
|
Quartz uses [rehype-citation](https://github.com/timlrx/rehype-citation) to support parsing of a BibTex bibliography file.
|
||||||
|
|
||||||
|
Under the default configuration, a citation key `[@templeton2024scaling]` will be exported as `(Templeton et al., 2024)`.
|
||||||
|
|
||||||
|
> [!example]- BibTex file
|
||||||
|
>
|
||||||
|
> ```bib title="bibliography.bib"
|
||||||
|
> @article{templeton2024scaling,
|
||||||
|
> title={Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnet},
|
||||||
|
> author={Templeton, Adly and Conerly, Tom and Marcus, Jonathan and Lindsey, Jack and Bricken, Trenton and Chen, Brian and Pearce, Adam and Citro, Craig and Ameisen, Emmanuel and Jones, Andy and Cunningham, Hoagy and Turner, Nicholas L and McDougall, Callum and MacDiarmid, Monte and Freeman, C. Daniel and Sumers, Theodore R. and Rees, Edward and Batson, Joshua and Jermyn, Adam and Carter, Shan and Olah, Chris and Henighan, Tom},
|
||||||
|
> year={2024},
|
||||||
|
> journal={Transformer Circuits Thread},
|
||||||
|
> url={https://transformer-circuits.pub/2024/scaling-monosemanticity/index.html}
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
|
> [!note] Behaviour of references
|
||||||
|
>
|
||||||
|
> By default, the references will be included at the end of the file. To control where the references to be included, uses `[^ref]`
|
||||||
|
>
|
||||||
|
> Refer to `rehype-citation` docs for more information.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
Citation parsing is a functionality of the [[plugins/Citations|Citation]] plugin. **This plugin is not enabled by default**. See the plugin page for customization options.
|
@ -3,5 +3,5 @@ Quartz comes shipped with a Docker image that will allow you to preview your Qua
|
|||||||
You can run the below one-liner to run Quartz in Docker.
|
You can run the below one-liner to run Quartz in Docker.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run --rm -itp 8080:8080 $(docker build -q .)
|
docker run --rm -itp 8080:8080 -p 3001:3001 -v ./content:/usr/src/app/content $(docker build -q .)
|
||||||
```
|
```
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
Quartz emits an RSS feed for all the content on your site by generating an `index.xml` file that RSS readers can subscribe to. Because of the RSS spec, this requires the `baseUrl` property in your [[configuration]] to be set properly for RSS readers to pick it up properly.
|
Quartz emits an RSS feed for all the content on your site by generating an `index.xml` file that RSS readers can subscribe to. Because of the RSS spec, this requires the `baseUrl` property in your [[configuration]] to be set properly for RSS readers to pick it up properly.
|
||||||
|
|
||||||
|
> [!info]
|
||||||
|
> After deploying, the generated RSS link will be available at `https://${baseUrl}/index.xml` by default.
|
||||||
|
>
|
||||||
|
> The `index.xml` path can be customized by passing the `rssSlug` option to the [[ContentIndex]] plugin.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
This functionality is provided by the [[ContentIndex]] plugin. See the plugin page for customization options.
|
This functionality is provided by the [[ContentIndex]] plugin. See the plugin page for customization options.
|
||||||
|
28
docs/features/Roam Research compatibility.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
title: "Roam Research Compatibility"
|
||||||
|
tags:
|
||||||
|
- feature/transformer
|
||||||
|
---
|
||||||
|
|
||||||
|
[Roam Research](https://roamresearch.com) is a note-taking tool that organizes your knowledge graph in a unique and interconnected way.
|
||||||
|
|
||||||
|
Quartz supports transforming the special Markdown syntax from Roam Research (like `{{[[components]]}}` and other formatting) into
|
||||||
|
regular Markdown via the [[RoamFlavoredMarkdown]] plugin.
|
||||||
|
|
||||||
|
```typescript title="quartz.config.ts"
|
||||||
|
plugins: {
|
||||||
|
transformers: [
|
||||||
|
// ...
|
||||||
|
Plugin.RoamFlavoredMarkdown(),
|
||||||
|
Plugin.ObsidianFlavoredMarkdown(),
|
||||||
|
// ...
|
||||||
|
],
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!warning]
|
||||||
|
> As seen above placement of `Plugin.RoamFlavoredMarkdown()` within `quartz.config.ts` is very important. It must come before `Plugin.ObsidianFlavoredMarkdown()`.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
This functionality is provided by the [[RoamFlavoredMarkdown]] plugin. See the plugin page for customization options.
|
@ -9,6 +9,7 @@ A backlink for a note is a link from another note to that note. Links in the bac
|
|||||||
## Customization
|
## Customization
|
||||||
|
|
||||||
- Removing backlinks: delete all usages of `Component.Backlinks()` from `quartz.layout.ts`.
|
- Removing backlinks: delete all usages of `Component.Backlinks()` from `quartz.layout.ts`.
|
||||||
|
- Hide when empty: hide `Backlinks` if given page doesn't contain any backlinks (default to `true`). To disable this, use `Component.Backlinks({ hideWhenEmpty: false })`.
|
||||||
- Component: `quartz/components/Backlinks.tsx`
|
- Component: `quartz/components/Backlinks.tsx`
|
||||||
- Style: `quartz/components/styles/backlinks.scss`
|
- Style: `quartz/components/styles/backlinks.scss`
|
||||||
- Script: `quartz/components/scripts/search.inline.ts`
|
- Script: `quartz/components/scripts/search.inline.ts`
|
||||||
|
@ -19,7 +19,6 @@ Component.Breadcrumbs({
|
|||||||
spacerSymbol: "❯", // symbol between crumbs
|
spacerSymbol: "❯", // symbol between crumbs
|
||||||
rootName: "Home", // name of first/root element
|
rootName: "Home", // name of first/root element
|
||||||
resolveFrontmatterTitle: true, // whether to resolve folder names through frontmatter titles
|
resolveFrontmatterTitle: true, // whether to resolve folder names through frontmatter titles
|
||||||
hideOnRoot: true, // whether to hide breadcrumbs on root `index.md` page
|
|
||||||
showCurrentPage: true, // whether to display the current page in the breadcrumbs
|
showCurrentPage: true, // whether to display the current page in the breadcrumbs
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -63,6 +63,18 @@ type Options = {
|
|||||||
category: string
|
category: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
|
||||||
|
// Url to folder with custom themes
|
||||||
|
// defaults to 'https://${cfg.baseUrl}/static/giscus'
|
||||||
|
themeUrl?: string
|
||||||
|
|
||||||
|
// filename for light theme .css file
|
||||||
|
// defaults to 'light'
|
||||||
|
lightTheme?: string
|
||||||
|
|
||||||
|
// filename for dark theme .css file
|
||||||
|
// defaults to 'dark'
|
||||||
|
darkTheme?: string
|
||||||
|
|
||||||
// how to map pages -> discussions
|
// how to map pages -> discussions
|
||||||
// defaults to 'url'
|
// defaults to 'url'
|
||||||
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
||||||
@ -81,3 +93,35 @@ type Options = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Custom CSS theme
|
||||||
|
|
||||||
|
Quartz supports custom theme for Giscus. To use a custom CSS theme, place the `.css` file inside the `quartz/static` folder and set the configuration values.
|
||||||
|
|
||||||
|
For example, if you have a light theme `light-theme.css`, a dark theme `dark-theme.css`, and your Quartz site is hosted at `https://example.com/`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
afterBody: [
|
||||||
|
Component.Comments({
|
||||||
|
provider: 'giscus',
|
||||||
|
options: {
|
||||||
|
// Other options
|
||||||
|
|
||||||
|
themeUrl: "https://example.com/static/giscus", // corresponds to quartz/static/giscus/
|
||||||
|
lightTheme: "light-theme", // corresponds to light-theme.css in quartz/static/giscus/
|
||||||
|
darkTheme: "dark-theme", // corresponds to dark-theme.css quartz/static/giscus/
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Conditionally display comments
|
||||||
|
|
||||||
|
Quartz can conditionally display the comment box based on a field `comments` in the frontmatter. By default, all pages will display comments, to disable it for a specific page, set `comments` to `false`.
|
||||||
|
|
||||||
|
```
|
||||||
|
---
|
||||||
|
title: Comments disabled here!
|
||||||
|
comments: false
|
||||||
|
---
|
||||||
|
```
|
||||||
|
@ -27,12 +27,10 @@ Component.Explorer({
|
|||||||
folderClickBehavior: "collapse", // what happens when you click a folder ("link" to navigate to folder page on click or "collapse" to collapse folder on click)
|
folderClickBehavior: "collapse", // what happens when you click a folder ("link" to navigate to folder page on click or "collapse" to collapse folder on click)
|
||||||
folderDefaultState: "collapsed", // default state of folders ("collapsed" or "open")
|
folderDefaultState: "collapsed", // default state of folders ("collapsed" or "open")
|
||||||
useSavedState: true, // whether to use local storage to save "state" (which folders are opened) of explorer
|
useSavedState: true, // whether to use local storage to save "state" (which folders are opened) of explorer
|
||||||
// Sort order: folders first, then files. Sort folders and files alphabetically
|
// omitted but shown later
|
||||||
sortFn: (a, b) => {
|
sortFn: ...,
|
||||||
... // default implementation shown later
|
filterFn: ...,
|
||||||
},
|
mapFn: ...,
|
||||||
filterFn: filterFn: (node) => node.name !== "tags", // filters out 'tags' folder
|
|
||||||
mapFn: undefined,
|
|
||||||
// what order to apply functions in
|
// what order to apply functions in
|
||||||
order: ["filter", "map", "sort"],
|
order: ["filter", "map", "sort"],
|
||||||
})
|
})
|
||||||
@ -54,17 +52,23 @@ Want to customize it even more?
|
|||||||
## Advanced customization
|
## Advanced customization
|
||||||
|
|
||||||
This component allows you to fully customize all of its behavior. You can pass a custom `sort`, `filter` and `map` function.
|
This component allows you to fully customize all of its behavior. You can pass a custom `sort`, `filter` and `map` function.
|
||||||
All functions you can pass work with the `FileNode` class, which has the following properties:
|
All functions you can pass work with the `FileTrieNode` class, which has the following properties:
|
||||||
|
|
||||||
```ts title="quartz/components/ExplorerNode.tsx" {2-5}
|
```ts title="quartz/components/Explorer.tsx"
|
||||||
export class FileNode {
|
class FileTrieNode {
|
||||||
children: FileNode[] // children of current node
|
isFolder: boolean
|
||||||
name: string // last part of slug
|
children: Array<FileTrieNode>
|
||||||
displayName: string // what actually should be displayed in the explorer
|
data: ContentDetails | null
|
||||||
file: QuartzPluginData | null // if node is a file, this is the file's metadata. See `QuartzPluginData` for more detail
|
}
|
||||||
depth: number // depth of current node
|
```
|
||||||
|
|
||||||
... // rest of implementation
|
```ts title="quartz/plugins/emitters/contentIndex.tsx"
|
||||||
|
export type ContentDetails = {
|
||||||
|
slug: FullSlug
|
||||||
|
title: string
|
||||||
|
links: SimpleSlug[]
|
||||||
|
tags: string[]
|
||||||
|
content: string
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -74,15 +78,14 @@ Every function you can pass is optional. By default, only a `sort` function will
|
|||||||
// Sort order: folders first, then files. Sort folders and files alphabetically
|
// Sort order: folders first, then files. Sort folders and files alphabetically
|
||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
sortFn: (a, b) => {
|
sortFn: (a, b) => {
|
||||||
if ((!a.file && !b.file) || (a.file && b.file)) {
|
if ((!a.isFolder && !b.isFolder) || (a.isFolder && b.isFolder)) {
|
||||||
// sensitivity: "base": Only strings that differ in base letters compare as unequal. Examples: a ≠ b, a = á, a = A
|
|
||||||
// numeric: true: Whether numeric collation should be used, such that "1" < "2" < "10"
|
|
||||||
return a.displayName.localeCompare(b.displayName, undefined, {
|
return a.displayName.localeCompare(b.displayName, undefined, {
|
||||||
numeric: true,
|
numeric: true,
|
||||||
sensitivity: "base",
|
sensitivity: "base",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (a.file && !b.file) {
|
|
||||||
|
if (!a.isFolder && b.isFolder) {
|
||||||
return 1
|
return 1
|
||||||
} else {
|
} else {
|
||||||
return -1
|
return -1
|
||||||
@ -100,41 +103,23 @@ For more information on how to use `sort`, `filter` and `map`, you can check [Ar
|
|||||||
Type definitions look like this:
|
Type definitions look like this:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
sortFn: (a: FileNode, b: FileNode) => number
|
type SortFn = (a: FileTrieNode, b: FileTrieNode) => number
|
||||||
filterFn: (node: FileNode) => boolean
|
type FilterFn = (node: FileTrieNode) => boolean
|
||||||
mapFn: (node: FileNode) => void
|
type MapFn = (node: FileTrieNode) => void
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!tip]
|
|
||||||
> You can check if a `FileNode` is a folder or a file like this:
|
|
||||||
>
|
|
||||||
> ```ts
|
|
||||||
> if (node.file) {
|
|
||||||
> // node is a file
|
|
||||||
> } else {
|
|
||||||
> // node is a folder
|
|
||||||
> }
|
|
||||||
> ```
|
|
||||||
|
|
||||||
## Basic examples
|
## Basic examples
|
||||||
|
|
||||||
These examples show the basic usage of `sort`, `map` and `filter`.
|
These examples show the basic usage of `sort`, `map` and `filter`.
|
||||||
|
|
||||||
### Use `sort` to put files first
|
### Use `sort` to put files first
|
||||||
|
|
||||||
Using this example, the explorer will alphabetically sort everything, but put all **files** above all **folders**.
|
Using this example, the explorer will alphabetically sort everything.
|
||||||
|
|
||||||
```ts title="quartz.layout.ts"
|
```ts title="quartz.layout.ts"
|
||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
sortFn: (a, b) => {
|
sortFn: (a, b) => {
|
||||||
if ((!a.file && !b.file) || (a.file && b.file)) {
|
return a.displayName.localeCompare(b.displayName)
|
||||||
return a.displayName.localeCompare(b.displayName)
|
|
||||||
}
|
|
||||||
if (a.file && !b.file) {
|
|
||||||
return -1
|
|
||||||
} else {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@ -147,42 +132,47 @@ Using this example, the display names of all `FileNodes` (folders + files) will
|
|||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
mapFn: (node) => {
|
mapFn: (node) => {
|
||||||
node.displayName = node.displayName.toUpperCase()
|
node.displayName = node.displayName.toUpperCase()
|
||||||
|
return node
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Remove list of elements (`filter`)
|
### Remove list of elements (`filter`)
|
||||||
|
|
||||||
Using this example, you can remove elements from your explorer by providing an array of folders/files using the `omit` set.
|
Using this example, you can remove elements from your explorer by providing an array of folders/files to exclude.
|
||||||
|
Note that this example filters on the title but you can also do it via slug or any other field available on `FileTrieNode`.
|
||||||
|
|
||||||
```ts title="quartz.layout.ts"
|
```ts title="quartz.layout.ts"
|
||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
filterFn: (node) => {
|
filterFn: (node) => {
|
||||||
// set containing names of everything you want to filter out
|
// set containing names of everything you want to filter out
|
||||||
const omit = new Set(["authoring content", "tags", "hosting"])
|
const omit = new Set(["authoring content", "tags", "advanced"])
|
||||||
return !omit.has(node.name.toLowerCase())
|
|
||||||
|
// can also use node.slug or by anything on node.data
|
||||||
|
// note that node.data is only present for files that exist on disk
|
||||||
|
// (e.g. implicit folder nodes that have no associated index.md)
|
||||||
|
return !omit.has(node.displayName.toLowerCase())
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
You can customize this by changing the entries of the `omit` set. Simply add all folder or file names you want to remove.
|
|
||||||
|
|
||||||
### Remove files by tag
|
### Remove files by tag
|
||||||
|
|
||||||
You can access the frontmatter of a file by `node.file?.frontmatter?`. This allows you to filter out files based on their frontmatter, for example by their tags.
|
You can access the tags of a file by `node.data.tags`.
|
||||||
|
|
||||||
```ts title="quartz.layout.ts"
|
```ts title="quartz.layout.ts"
|
||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
filterFn: (node) => {
|
filterFn: (node) => {
|
||||||
// exclude files with the tag "explorerexclude"
|
// exclude files with the tag "explorerexclude"
|
||||||
return node.file?.frontmatter?.tags?.includes("explorerexclude") !== true
|
return node.data.tags?.includes("explorerexclude") !== true
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Show every element in explorer
|
### Show every element in explorer
|
||||||
|
|
||||||
To override the default filter function that removes the `tags` folder from the explorer, you can set the filter function to `undefined`.
|
By default, the explorer will filter out the `tags` folder.
|
||||||
|
To override the default filter function, you can set the filter function to `undefined`.
|
||||||
|
|
||||||
```ts title="quartz.layout.ts"
|
```ts title="quartz.layout.ts"
|
||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
@ -194,10 +184,12 @@ Component.Explorer({
|
|||||||
|
|
||||||
> [!tip]
|
> [!tip]
|
||||||
> When writing more complicated functions, the `layout` file can start to look very cramped.
|
> When writing more complicated functions, the `layout` file can start to look very cramped.
|
||||||
> You can fix this by defining your functions in another file.
|
> You can fix this by defining your sort functions outside of the component
|
||||||
|
> and passing it in.
|
||||||
>
|
>
|
||||||
> ```ts title="functions.ts"
|
> ```ts title="quartz.layout.ts"
|
||||||
> import { Options } from "./quartz/components/ExplorerNode"
|
> import { Options } from "./quartz/components/ExplorerNode"
|
||||||
|
>
|
||||||
> export const mapFn: Options["mapFn"] = (node) => {
|
> export const mapFn: Options["mapFn"] = (node) => {
|
||||||
> // implement your function here
|
> // implement your function here
|
||||||
> }
|
> }
|
||||||
@ -207,16 +199,12 @@ Component.Explorer({
|
|||||||
> export const sortFn: Options["sortFn"] = (a, b) => {
|
> export const sortFn: Options["sortFn"] = (a, b) => {
|
||||||
> // implement your function here
|
> // implement your function here
|
||||||
> }
|
> }
|
||||||
> ```
|
|
||||||
>
|
>
|
||||||
> You can then import them like this:
|
|
||||||
>
|
|
||||||
> ```ts title="quartz.layout.ts"
|
|
||||||
> import { mapFn, filterFn, sortFn } from "./functions.ts"
|
|
||||||
> Component.Explorer({
|
> Component.Explorer({
|
||||||
> mapFn: mapFn,
|
> // ... your other options
|
||||||
> filterFn: filterFn,
|
> mapFn,
|
||||||
> sortFn: sortFn,
|
> filterFn,
|
||||||
|
> sortFn,
|
||||||
> })
|
> })
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
@ -227,93 +215,11 @@ To add emoji prefixes (📁 for folders, 📄 for files), you could use a map fu
|
|||||||
```ts title="quartz.layout.ts"
|
```ts title="quartz.layout.ts"
|
||||||
Component.Explorer({
|
Component.Explorer({
|
||||||
mapFn: (node) => {
|
mapFn: (node) => {
|
||||||
// dont change name of root node
|
if (node.isFolder) {
|
||||||
if (node.depth > 0) {
|
node.displayName = "📁 " + node.displayName
|
||||||
// set emoji for file/folder
|
} else {
|
||||||
if (node.file) {
|
node.displayName = "📄 " + node.displayName
|
||||||
node.displayName = "📄 " + node.displayName
|
|
||||||
} else {
|
|
||||||
node.displayName = "📁 " + node.displayName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Putting it all together
|
|
||||||
|
|
||||||
In this example, we're going to customize the explorer by using functions from examples above to [[#Add emoji prefix | add emoji prefixes]], [[#remove-list-of-elements-filter| filter out some folders]] and [[#use-sort-to-put-files-first | sort with files above folders]].
|
|
||||||
|
|
||||||
```ts title="quartz.layout.ts"
|
|
||||||
Component.Explorer({
|
|
||||||
filterFn: sampleFilterFn,
|
|
||||||
mapFn: sampleMapFn,
|
|
||||||
sortFn: sampleSortFn,
|
|
||||||
order: ["filter", "sort", "map"],
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
Notice how we customized the `order` array here. This is done because the default order applies the `sort` function last. While this normally works well, it would cause unintended behavior here, since we changed the first characters of all display names. In our example, `sort` would be applied based off the emoji prefix instead of the first _real_ character.
|
|
||||||
|
|
||||||
To fix this, we just changed around the order and apply the `sort` function before changing the display names in the `map` function.
|
|
||||||
|
|
||||||
### Use `sort` with pre-defined sort order
|
|
||||||
|
|
||||||
Here's another example where a map containing file/folder names (as slugs) is used to define the sort order of the explorer in quartz. All files/folders that aren't listed inside of `nameOrderMap` will appear at the top of that folders hierarchy level.
|
|
||||||
|
|
||||||
It's also worth mentioning, that the smaller the number set in `nameOrderMap`, the higher up the entry will be in the explorer. Incrementing every folder/file by 100, makes ordering files in their folders a lot easier. Lastly, this example still allows you to use a `mapFn` or frontmatter titles to change display names, as it uses slugs for `nameOrderMap` (which is unaffected by display name changes).
|
|
||||||
|
|
||||||
```ts title="quartz.layout.ts"
|
|
||||||
Component.Explorer({
|
|
||||||
sortFn: (a, b) => {
|
|
||||||
const nameOrderMap: Record<string, number> = {
|
|
||||||
"poetry-folder": 100,
|
|
||||||
"essay-folder": 200,
|
|
||||||
"research-paper-file": 201,
|
|
||||||
"dinosaur-fossils-file": 300,
|
|
||||||
"other-folder": 400,
|
|
||||||
}
|
|
||||||
|
|
||||||
let orderA = 0
|
|
||||||
let orderB = 0
|
|
||||||
|
|
||||||
if (a.file && a.file.slug) {
|
|
||||||
orderA = nameOrderMap[a.file.slug] || 0
|
|
||||||
} else if (a.name) {
|
|
||||||
orderA = nameOrderMap[a.name] || 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b.file && b.file.slug) {
|
|
||||||
orderB = nameOrderMap[b.file.slug] || 0
|
|
||||||
} else if (b.name) {
|
|
||||||
orderB = nameOrderMap[b.name] || 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return orderA - orderB
|
|
||||||
},
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
For reference, this is how the quartz explorer window would look like with that example:
|
|
||||||
|
|
||||||
```
|
|
||||||
📖 Poetry Folder
|
|
||||||
📑 Essay Folder
|
|
||||||
⚗️ Research Paper File
|
|
||||||
🦴 Dinosaur Fossils File
|
|
||||||
🔮 Other Folder
|
|
||||||
```
|
|
||||||
|
|
||||||
And this is how the file structure would look like:
|
|
||||||
|
|
||||||
```
|
|
||||||
index.md
|
|
||||||
poetry-folder
|
|
||||||
index.md
|
|
||||||
essay-folder
|
|
||||||
index.md
|
|
||||||
research-paper-file.md
|
|
||||||
dinosaur-fossils-file.md
|
|
||||||
other-folder
|
|
||||||
index.md
|
|
||||||
```
|
|
||||||
|
@ -36,6 +36,7 @@ Component.Graph({
|
|||||||
opacityScale: 1, // how quickly do we fade out the labels when zooming out?
|
opacityScale: 1, // how quickly do we fade out the labels when zooming out?
|
||||||
removeTags: [], // what tags to remove from the graph
|
removeTags: [], // what tags to remove from the graph
|
||||||
showTags: true, // whether to show tags in the graph
|
showTags: true, // whether to show tags in the graph
|
||||||
|
enableRadial: false, // whether to constrain the graph, similar to Obsidian
|
||||||
},
|
},
|
||||||
globalGraph: {
|
globalGraph: {
|
||||||
drag: true,
|
drag: true,
|
||||||
@ -49,6 +50,7 @@ Component.Graph({
|
|||||||
opacityScale: 1,
|
opacityScale: 1,
|
||||||
removeTags: [], // what tags to remove from the graph
|
removeTags: [], // what tags to remove from the graph
|
||||||
showTags: true, // whether to show tags in the graph
|
showTags: true, // whether to show tags in the graph
|
||||||
|
enableRadial: true, // whether to constrain the graph, similar to Obsidian
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
44
docs/features/reader mode.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
title: Reader Mode
|
||||||
|
tags:
|
||||||
|
- component
|
||||||
|
---
|
||||||
|
|
||||||
|
Reader Mode is a feature that allows users to focus on the content by hiding the sidebars and other UI elements. When enabled, it provides a clean, distraction-free reading experience.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Reader Mode is enabled by default. To disable it, you can remove the component from your layout configuration in `quartz.layout.ts`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Remove or comment out this line
|
||||||
|
Component.ReaderMode(),
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
The Reader Mode toggle appears as a button with a book icon. When clicked:
|
||||||
|
|
||||||
|
- Sidebars are hidden
|
||||||
|
- Hovering over the content area reveals the sidebars temporarily
|
||||||
|
|
||||||
|
Unlike Dark Mode, Reader Mode state is not persisted between page reloads but is maintained during SPA navigation within the site.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
You can customize the appearance of Reader Mode through CSS variables and styles. The component uses the following classes:
|
||||||
|
|
||||||
|
- `.readermode`: The toggle button
|
||||||
|
- `.readerIcon`: The book icon
|
||||||
|
- `[reader-mode="on"]`: Applied to the root element when Reader Mode is active
|
||||||
|
|
||||||
|
Example customization in your custom CSS:
|
||||||
|
|
||||||
|
```scss
|
||||||
|
.readermode {
|
||||||
|
// Customize the button
|
||||||
|
svg {
|
||||||
|
stroke: var(--custom-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
19
docs/features/social images.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
title: "Social Media Preview Cards"
|
||||||
|
---
|
||||||
|
|
||||||
|
A lot of social media platforms can display a rich preview for your website when sharing a link (most notably, a cover image, a title and a description).
|
||||||
|
|
||||||
|
Quartz can also dynamically generate and use new cover images for every page to be used in link previews on social media for you.
|
||||||
|
|
||||||
|
## Showcase
|
||||||
|
|
||||||
|
After enabling the [[CustomOgImages]] emitter plugin, the social media link preview for [[authoring content | Authoring Content]] looks like this:
|
||||||
|
|
||||||
|
| Light | Dark |
|
||||||
|
| ----------------------------------- | ---------------------------------- |
|
||||||
|
| ![[social-image-preview-light.png]] | ![[social-image-preview-dark.png]] |
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
This functionality is provided by the [[CustomOgImages]] plugin. See the plugin page for customization options.
|
@ -247,6 +247,28 @@ server {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using Apache
|
||||||
|
|
||||||
|
Here's an example of how to do this with Apache:
|
||||||
|
|
||||||
|
```apache title=".htaccess"
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
ErrorDocument 404 /404.html
|
||||||
|
|
||||||
|
# Rewrite rule for .html extension removal (with directory check)
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.html -f
|
||||||
|
RewriteRule ^(.*)$ $1.html [L]
|
||||||
|
|
||||||
|
# Handle directory requests explicitly
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -d
|
||||||
|
RewriteRule ^(.*)/$ $1/index.html [L]
|
||||||
|
```
|
||||||
|
|
||||||
|
Don't forget to activate brotli / gzip compression.
|
||||||
|
|
||||||
### Using Caddy
|
### Using Caddy
|
||||||
|
|
||||||
Here's and example of how to do this with Caddy:
|
Here's and example of how to do this with Caddy:
|
||||||
|
BIN
docs/images/custom-social-image-preview-dark.png
Normal file
After Width: | Height: | Size: 129 KiB |
BIN
docs/images/custom-social-image-preview-light.png
Normal file
After Width: | Height: | Size: 132 KiB |
Before Width: | Height: | Size: 65 KiB |
BIN
docs/images/quartz-layout-desktop.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/quartz-layout-mobile.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/quartz-layout-tablet.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
docs/images/social-image-preview-dark.png
Normal file
After Width: | Height: | Size: 139 KiB |
BIN
docs/images/social-image-preview-light.png
Normal file
After Width: | Height: | Size: 134 KiB |
@ -31,13 +31,13 @@ If you prefer instructions in a video format you can try following Nicole van de
|
|||||||
|
|
||||||
## 🔧 Features
|
## 🔧 Features
|
||||||
|
|
||||||
- [[Obsidian compatibility]], [[full-text search]], [[graph view]], note transclusion, [[wikilinks]], [[backlinks]], [[features/Latex|Latex]], [[syntax highlighting]], [[popover previews]], [[Docker Support]], [[i18n|internationalization]], [[comments]] and [many more](./features) right out of the box
|
- [[Obsidian compatibility]], [[full-text search]], [[graph view]], [[wikilinks|wikilinks, transclusions]], [[backlinks]], [[features/Latex|Latex]], [[syntax highlighting]], [[popover previews]], [[Docker Support]], [[i18n|internationalization]], [[comments]] and [many more](./features/) right out of the box
|
||||||
- Hot-reload for both configuration and content
|
- Hot-reload on configuration edits and incremental rebuilds for content edits
|
||||||
- Simple JSX layouts and [[creating components|page components]]
|
- Simple JSX layouts and [[creating components|page components]]
|
||||||
- [[SPA Routing|Ridiculously fast page loads]] and tiny bundle sizes
|
- [[SPA Routing|Ridiculously fast page loads]] and tiny bundle sizes
|
||||||
- Fully-customizable parsing, filtering, and page generation through [[making plugins|plugins]]
|
- Fully-customizable parsing, filtering, and page generation through [[making plugins|plugins]]
|
||||||
|
|
||||||
For a comprehensive list of features, visit the [features page](/features). You can read more about the _why_ behind these features on the [[philosophy]] page and a technical overview on the [[architecture]] page.
|
For a comprehensive list of features, visit the [features page](./features/). You can read more about the _why_ behind these features on the [[philosophy]] page and a technical overview on the [[architecture]] page.
|
||||||
|
|
||||||
### 🚧 Troubleshooting + Updating
|
### 🚧 Troubleshooting + Updating
|
||||||
|
|
||||||
|
93
docs/layout-components.md
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
---
|
||||||
|
title: Higher-Order Layout Components
|
||||||
|
---
|
||||||
|
|
||||||
|
Quartz provides several higher-order components that help with layout composition and responsive design. These components wrap other components to add additional functionality or modify their behavior.
|
||||||
|
|
||||||
|
## `Flex` Component
|
||||||
|
|
||||||
|
The `Flex` component creates a [flexible box layout](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) that can arrange child components in various ways. It's particularly useful for creating responsive layouts and organizing components in rows or columns.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
type FlexConfig = {
|
||||||
|
components: {
|
||||||
|
Component: QuartzComponent
|
||||||
|
grow?: boolean // whether component should grow to fill space
|
||||||
|
shrink?: boolean // whether component should shrink if needed
|
||||||
|
basis?: string // initial main size of the component
|
||||||
|
order?: number // order in flex container
|
||||||
|
align?: "start" | "end" | "center" | "stretch" // cross-axis alignment
|
||||||
|
justify?: "start" | "end" | "center" | "between" | "around" // main-axis alignment
|
||||||
|
}[]
|
||||||
|
direction?: "row" | "row-reverse" | "column" | "column-reverse"
|
||||||
|
wrap?: "nowrap" | "wrap" | "wrap-reverse"
|
||||||
|
gap?: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
Component.Flex({
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
Component: Component.Search(),
|
||||||
|
grow: true, // Search will grow to fill available space
|
||||||
|
},
|
||||||
|
{ Component: Component.Darkmode() }, // Darkmode keeps its natural size
|
||||||
|
],
|
||||||
|
direction: "row",
|
||||||
|
gap: "1rem",
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## `MobileOnly` Component
|
||||||
|
|
||||||
|
The `MobileOnly` component is a wrapper that makes its child component only visible on mobile devices. This is useful for creating responsive layouts where certain components should only appear on smaller screens.
|
||||||
|
|
||||||
|
### Example Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
Component.MobileOnly(Component.Spacer())
|
||||||
|
```
|
||||||
|
|
||||||
|
## `DesktopOnly` Component
|
||||||
|
|
||||||
|
The `DesktopOnly` component is the counterpart to `MobileOnly`. It makes its child component only visible on desktop devices. This helps create responsive layouts where certain components should only appear on larger screens.
|
||||||
|
|
||||||
|
### Example Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
Component.DesktopOnly(Component.TableOfContents())
|
||||||
|
```
|
||||||
|
|
||||||
|
## `ConditionalRender` Component
|
||||||
|
|
||||||
|
The `ConditionalRender` component is a wrapper that conditionally renders its child component based on a provided condition function. This is useful for creating dynamic layouts where components should only appear under certain conditions.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
type ConditionalRenderConfig = {
|
||||||
|
component: QuartzComponent
|
||||||
|
condition: (props: QuartzComponentProps) => boolean
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
Component.ConditionalRender({
|
||||||
|
component: Component.Search(),
|
||||||
|
condition: (props) => props.displayClass !== "fullpage",
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The example above would only render the Search component when the page is not in fullpage mode.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
Component.ConditionalRender({
|
||||||
|
component: Component.Breadcrumbs(),
|
||||||
|
condition: (page) => page.fileData.slug !== "index",
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
The example above would hide breadcrumbs on the root `index.md` page.
|
@ -13,15 +13,19 @@ export interface FullPageLayout {
|
|||||||
beforeBody: QuartzComponent[] // laid out vertically
|
beforeBody: QuartzComponent[] // laid out vertically
|
||||||
pageBody: QuartzComponent // single component
|
pageBody: QuartzComponent // single component
|
||||||
afterBody: QuartzComponent[] // laid out vertically
|
afterBody: QuartzComponent[] // laid out vertically
|
||||||
left: QuartzComponent[] // vertical on desktop, horizontal on mobile
|
left: QuartzComponent[] // vertical on desktop and tablet, horizontal on mobile
|
||||||
right: QuartzComponent[] // vertical on desktop, horizontal on mobile
|
right: QuartzComponent[] // vertical on desktop, horizontal on tablet and mobile
|
||||||
footer: QuartzComponent // single component
|
footer: QuartzComponent // single component
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
These correspond to following parts of the page:
|
These correspond to following parts of the page:
|
||||||
|
|
||||||
![[quartz layout.png|800]]
|
| Layout | Preview |
|
||||||
|
| ------------------------------- | ----------------------------------- |
|
||||||
|
| Desktop (width > 1200px) | ![[quartz-layout-desktop.png\|800]] |
|
||||||
|
| Tablet (800px < width < 1200px) | ![[quartz-layout-tablet.png\|800]] |
|
||||||
|
| Mobile (width < 800px) | ![[quartz-layout-mobile.png\|800]] |
|
||||||
|
|
||||||
> [!note]
|
> [!note]
|
||||||
> There are two additional layout fields that are _not_ shown in the above diagram.
|
> There are two additional layout fields that are _not_ shown in the above diagram.
|
||||||
@ -31,7 +35,26 @@ These correspond to following parts of the page:
|
|||||||
|
|
||||||
Quartz **components**, like plugins, can take in additional properties as configuration options. If you're familiar with React terminology, you can think of them as Higher-order Components.
|
Quartz **components**, like plugins, can take in additional properties as configuration options. If you're familiar with React terminology, you can think of them as Higher-order Components.
|
||||||
|
|
||||||
See [a list of all the components](component.md) for all available components along with their configuration options. You can also checkout the guide on [[creating components]] if you're interested in further customizing the behaviour of Quartz.
|
See [a list of all the components](component.md) for all available components along with their configuration options. Additionally, Quartz provides several built-in higher-order components for layout composition - see [[layout-components]] for more details.
|
||||||
|
|
||||||
|
You can also checkout the guide on [[creating components]] if you're interested in further customizing the behaviour of Quartz.
|
||||||
|
|
||||||
|
### Layout breakpoints
|
||||||
|
|
||||||
|
Quartz has different layouts depending on the width the screen viewing the website.
|
||||||
|
|
||||||
|
The breakpoints for layouts can be configured in `variables.scss`.
|
||||||
|
|
||||||
|
- `mobile`: screen width below this size will use mobile layout.
|
||||||
|
- `desktop`: screen width above this size will use desktop layout.
|
||||||
|
- Screen width between `mobile` and `desktop` width will use the tablet layout.
|
||||||
|
|
||||||
|
```scss
|
||||||
|
$breakpoints: (
|
||||||
|
mobile: 800px,
|
||||||
|
desktop: 1200px,
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### Style
|
### Style
|
||||||
|
|
||||||
|
24
docs/plugins/Citations.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
title: "Citations"
|
||||||
|
tags:
|
||||||
|
- plugin/transformer
|
||||||
|
---
|
||||||
|
|
||||||
|
This plugin adds Citation support to Quartz.
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
> For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page.
|
||||||
|
|
||||||
|
This plugin accepts the following configuration options:
|
||||||
|
|
||||||
|
- `bibliographyFile`: the path to the bibliography file. Defaults to `./bibliography.bib`. This is relative to git source of your vault.
|
||||||
|
- `suppressBibliography`: whether to suppress the bibliography at the end of the document. Defaults to `false`.
|
||||||
|
- `linkCitations`: whether to link citations to the bibliography. Defaults to `false`.
|
||||||
|
- `csl`: the citation style to use. Defaults to `apa`. Reference [rehype-citation](https://rehype-citation.netlify.app/custom-csl) for more options.
|
||||||
|
- `prettyLink`: whether to use pretty links for citations. Defaults to `true`.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
- Category: Transformer
|
||||||
|
- Function name: `Plugin.Citations()`.
|
||||||
|
- Source: [`quartz/plugins/transformers/citations.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/citations.ts).
|
@ -17,6 +17,7 @@ This plugin accepts the following configuration options:
|
|||||||
- `enableRSS`: If `true` (default), produces an RSS feed (`index.xml`) with recent content updates.
|
- `enableRSS`: If `true` (default), produces an RSS feed (`index.xml`) with recent content updates.
|
||||||
- `rssLimit`: Defines the maximum number of entries to include in the RSS feed, helping to focus on the most recent or relevant content. Defaults to `10`.
|
- `rssLimit`: Defines the maximum number of entries to include in the RSS feed, helping to focus on the most recent or relevant content. Defaults to `10`.
|
||||||
- `rssFullHtml`: If `true`, the RSS feed includes full HTML content. Otherwise it includes just summaries.
|
- `rssFullHtml`: If `true`, the RSS feed includes full HTML content. Otherwise it includes just summaries.
|
||||||
|
- `rssSlug`: Slug to the generated RSS feed XML file. Defaults to `"index"`.
|
||||||
- `includeEmptyFiles`: If `true` (default), content files with no body text are included in the generated index and resources.
|
- `includeEmptyFiles`: If `true` (default), content files with no body text are included in the generated index and resources.
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
@ -13,6 +13,8 @@ This plugin accepts the following configuration options:
|
|||||||
|
|
||||||
- `priority`: The data sources to consult for date information. Highest priority first. Possible values are `"frontmatter"`, `"git"`, and `"filesystem"`. Defaults to `["frontmatter", "git", "filesystem"]`.
|
- `priority`: The data sources to consult for date information. Highest priority first. Possible values are `"frontmatter"`, `"git"`, and `"filesystem"`. Defaults to `["frontmatter", "git", "filesystem"]`.
|
||||||
|
|
||||||
|
When loading the frontmatter, the value of [[Frontmatter#List]] is used.
|
||||||
|
|
||||||
> [!warning]
|
> [!warning]
|
||||||
> If you rely on `git` for dates, make sure `defaultDateType` is set to `modified` in `quartz.config.ts`.
|
> If you rely on `git` for dates, make sure `defaultDateType` is set to `modified` in `quartz.config.ts`.
|
||||||
>
|
>
|
||||||
|
360
docs/plugins/CustomOgImages.md
Normal file
@ -0,0 +1,360 @@
|
|||||||
|
---
|
||||||
|
title: Custom OG Images
|
||||||
|
tags:
|
||||||
|
- feature/emitter
|
||||||
|
---
|
||||||
|
|
||||||
|
The Custom OG Images emitter plugin generates social media preview images for your pages. It uses [satori](https://github.com/vercel/satori) to convert HTML/CSS into images, allowing you to create beautiful and consistent social media preview cards for your content.
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
> For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Automatically generates social media preview images for each page
|
||||||
|
- Supports both light and dark mode themes
|
||||||
|
- Customizable through frontmatter properties
|
||||||
|
- Fallback to default image when needed
|
||||||
|
- Full control over image design through custom components
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
> [!info] Info
|
||||||
|
>
|
||||||
|
> The `baseUrl` property in your [[configuration]] must be set properly for social images to work correctly, as they require absolute paths.
|
||||||
|
|
||||||
|
This plugin accepts the following configuration options:
|
||||||
|
|
||||||
|
```typescript title="quartz.config.ts"
|
||||||
|
import { CustomOgImages } from "./quartz/plugins/emitters/ogImage"
|
||||||
|
|
||||||
|
const config: QuartzConfig = {
|
||||||
|
plugins: {
|
||||||
|
emitters: [
|
||||||
|
CustomOgImages({
|
||||||
|
colorScheme: "lightMode", // what colors to use for generating image, same as theme colors from config, valid values are "darkMode" and "lightMode"
|
||||||
|
width: 1200, // width to generate with (in pixels)
|
||||||
|
height: 630, // height to generate with (in pixels)
|
||||||
|
excludeRoot: false, // wether to exclude "/" index path to be excluded from auto generated images (false = use auto, true = use default og image)
|
||||||
|
imageStructure: defaultImage, // custom image component to use
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration Options
|
||||||
|
|
||||||
|
| Option | Type | Default | Description |
|
||||||
|
| ---------------- | --------- | ------------ | ----------------------------------------------------------------- |
|
||||||
|
| `colorScheme` | string | "lightMode" | Theme to use for generating images ("darkMode" or "lightMode") |
|
||||||
|
| `width` | number | 1200 | Width of the generated image in pixels |
|
||||||
|
| `height` | number | 630 | Height of the generated image in pixels |
|
||||||
|
| `excludeRoot` | boolean | false | Whether to exclude the root index page from auto-generated images |
|
||||||
|
| `imageStructure` | component | defaultImage | Custom component to use for image generation |
|
||||||
|
|
||||||
|
## Frontmatter Properties
|
||||||
|
|
||||||
|
The following properties can be used to customize your link previews:
|
||||||
|
|
||||||
|
| Property | Alias | Summary |
|
||||||
|
| ------------------- | ---------------- | ----------------------------------- |
|
||||||
|
| `socialDescription` | `description` | Description to be used for preview. |
|
||||||
|
| `socialImage` | `image`, `cover` | Link to preview image. |
|
||||||
|
|
||||||
|
The `socialImage` property should contain a link to an image either relative to `quartz/static`, or a full URL. If you have a folder for all your images in `quartz/static/my-images`, an example for `socialImage` could be `"my-images/cover.png"`. Alternatively, you can use a fully qualified URL like `"https://example.com/cover.png"`.
|
||||||
|
|
||||||
|
> [!info] Info
|
||||||
|
>
|
||||||
|
> The priority for what image will be used for the cover image looks like the following: `frontmatter property > generated image (if enabled) > default image`.
|
||||||
|
>
|
||||||
|
> The default image (`quartz/static/og-image.png`) will only be used as a fallback if nothing else is set. If the Custom OG Images emitter plugin is enabled, it will be treated as the new default per page, but can be overwritten by setting the `socialImage` frontmatter property for that page.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
You can fully customize how the images being generated look by passing your own component to `imageStructure`. This component takes JSX + some page metadata/config options and converts it to an image using [satori](https://github.com/vercel/satori). Vercel provides an [online playground](https://og-playground.vercel.app/) that can be used to preview how your JSX looks like as a picture. This is ideal for prototyping your custom design.
|
||||||
|
|
||||||
|
### Fonts
|
||||||
|
|
||||||
|
You will also be passed an array containing a header and a body font (where the first entry is header and the second is body). The fonts matches the ones selected in `theme.typography.header` and `theme.typography.body` from `quartz.config.ts` and will be passed in the format required by [`satori`](https://github.com/vercel/satori). To use them in CSS, use the `.name` property (e.g. `fontFamily: fonts[1].name` to use the "body" font family).
|
||||||
|
|
||||||
|
An example of a component using the header font could look like this:
|
||||||
|
|
||||||
|
```tsx title="socialImage.tsx"
|
||||||
|
export const myImage: SocialImageOptions["imageStructure"] = (...) => {
|
||||||
|
return <p style={{ fontFamily: fonts[0].name }}>Cool Header!</p>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!example]- Local fonts
|
||||||
|
>
|
||||||
|
> For cases where you use a local fonts under `static` folder, make sure to set the correct `@font-face` in `custom.scss`
|
||||||
|
>
|
||||||
|
> ```scss title="custom.scss"
|
||||||
|
> @font-face {
|
||||||
|
> font-family: "Newsreader";
|
||||||
|
> font-style: normal;
|
||||||
|
> font-weight: normal;
|
||||||
|
> font-display: swap;
|
||||||
|
> src: url("/static/Newsreader.woff2") format("woff2");
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> Then in `quartz/util/og.tsx`, you can load the Satori fonts like so:
|
||||||
|
>
|
||||||
|
> ```tsx title="quartz/util/og.tsx"
|
||||||
|
> import { joinSegments, QUARTZ } from "../path"
|
||||||
|
> import fs from "fs"
|
||||||
|
> import path from "path"
|
||||||
|
>
|
||||||
|
> const newsreaderFontPath = joinSegments(QUARTZ, "static", "Newsreader.woff2")
|
||||||
|
> export async function getSatoriFonts(headerFont: FontSpecification, bodyFont: FontSpecification) {
|
||||||
|
> // ... rest of implementation remains same
|
||||||
|
> const fonts: SatoriOptions["fonts"] = [
|
||||||
|
> ...headerFontData.map((data, idx) => ({
|
||||||
|
> name: headerFontName,
|
||||||
|
> data,
|
||||||
|
> weight: headerWeights[idx],
|
||||||
|
> style: "normal" as const,
|
||||||
|
> })),
|
||||||
|
> ...bodyFontData.map((data, idx) => ({
|
||||||
|
> name: bodyFontName,
|
||||||
|
> data,
|
||||||
|
> weight: bodyWeights[idx],
|
||||||
|
> style: "normal" as const,
|
||||||
|
> })),
|
||||||
|
> {
|
||||||
|
> name: "Newsreader",
|
||||||
|
> data: await fs.promises.readFile(path.resolve(newsreaderFontPath)),
|
||||||
|
> weight: 400,
|
||||||
|
> style: "normal" as const,
|
||||||
|
> },
|
||||||
|
> ]
|
||||||
|
>
|
||||||
|
> return fonts
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> This font then can be used with your custom structure.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Here are some example image components you can use as a starting point:
|
||||||
|
|
||||||
|
### Basic Example
|
||||||
|
|
||||||
|
This example will generate images that look as follows:
|
||||||
|
|
||||||
|
| Light | Dark |
|
||||||
|
| ------------------------------------------ | ----------------------------------------- |
|
||||||
|
| ![[custom-social-image-preview-light.png]] | ![[custom-social-image-preview-dark.png]] |
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import { SatoriOptions } from "satori/wasm"
|
||||||
|
import { GlobalConfiguration } from "../cfg"
|
||||||
|
import { SocialImageOptions, UserOpts } from "./imageHelper"
|
||||||
|
import { QuartzPluginData } from "../plugins/vfile"
|
||||||
|
|
||||||
|
export const customImage: SocialImageOptions["imageStructure"] = (
|
||||||
|
cfg: GlobalConfiguration,
|
||||||
|
userOpts: UserOpts,
|
||||||
|
title: string,
|
||||||
|
description: string,
|
||||||
|
fonts: SatoriOptions["fonts"],
|
||||||
|
fileData: QuartzPluginData,
|
||||||
|
) => {
|
||||||
|
// How many characters are allowed before switching to smaller font
|
||||||
|
const fontBreakPoint = 22
|
||||||
|
const useSmallerFont = title.length > fontBreakPoint
|
||||||
|
|
||||||
|
const { colorScheme } = userOpts
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "flex-start",
|
||||||
|
alignItems: "center",
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
backgroundColor: cfg.theme.colors[colorScheme].light,
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: "2.5rem",
|
||||||
|
paddingTop: "2rem",
|
||||||
|
paddingBottom: "2rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
color: cfg.theme.colors[colorScheme].dark,
|
||||||
|
fontSize: useSmallerFont ? 70 : 82,
|
||||||
|
marginLeft: "4rem",
|
||||||
|
textAlign: "center",
|
||||||
|
marginRight: "4rem",
|
||||||
|
fontFamily: fonts[0].name,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
color: cfg.theme.colors[colorScheme].dark,
|
||||||
|
fontSize: 44,
|
||||||
|
marginLeft: "8rem",
|
||||||
|
marginRight: "8rem",
|
||||||
|
lineClamp: 3,
|
||||||
|
fontFamily: fonts[1].name,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: "100%",
|
||||||
|
width: "2vw",
|
||||||
|
position: "absolute",
|
||||||
|
backgroundColor: cfg.theme.colors[colorScheme].tertiary,
|
||||||
|
opacity: 0.85,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Example
|
||||||
|
|
||||||
|
The following example includes a customized social image with a custom background and formatted date:
|
||||||
|
|
||||||
|
```typescript title="custom-og.tsx"
|
||||||
|
export const og: SocialImageOptions["Component"] = (
|
||||||
|
cfg: GlobalConfiguration,
|
||||||
|
fileData: QuartzPluginData,
|
||||||
|
{ colorScheme }: Options,
|
||||||
|
title: string,
|
||||||
|
description: string,
|
||||||
|
fonts: SatoriOptions["fonts"],
|
||||||
|
) => {
|
||||||
|
let created: string | undefined
|
||||||
|
let reading: string | undefined
|
||||||
|
if (fileData.dates) {
|
||||||
|
created = formatDate(getDate(cfg, fileData)!, cfg.locale)
|
||||||
|
}
|
||||||
|
const { minutes, text: _timeTaken, words: _words } = readingTime(fileData.text!)
|
||||||
|
reading = i18n(cfg.locale).components.contentMeta.readingTime({
|
||||||
|
minutes: Math.ceil(minutes),
|
||||||
|
})
|
||||||
|
|
||||||
|
const Li = [created, reading]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "relative",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "flex-start",
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
backgroundImage: `url("https://${cfg.baseUrl}/static/og-image.jpeg")`,
|
||||||
|
backgroundSize: "100% 100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
background: "radial-gradient(circle at center, transparent, rgba(0, 0, 0, 0.4) 70%)",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
flexDirection: "column",
|
||||||
|
justifyContent: "flex-start",
|
||||||
|
alignItems: "flex-start",
|
||||||
|
gap: "1.5rem",
|
||||||
|
paddingTop: "4rem",
|
||||||
|
paddingBottom: "4rem",
|
||||||
|
marginLeft: "4rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={`"https://${cfg.baseUrl}/static/icon.jpeg"`}
|
||||||
|
style={{
|
||||||
|
position: "relative",
|
||||||
|
backgroundClip: "border-box",
|
||||||
|
borderRadius: "6rem",
|
||||||
|
}}
|
||||||
|
width={80}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
textAlign: "left",
|
||||||
|
fontFamily: fonts[0].name,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h2
|
||||||
|
style={{
|
||||||
|
color: cfg.theme.colors[colorScheme].light,
|
||||||
|
fontSize: "3rem",
|
||||||
|
fontWeight: 700,
|
||||||
|
marginRight: "4rem",
|
||||||
|
fontFamily: fonts[0].name,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</h2>
|
||||||
|
<ul
|
||||||
|
style={{
|
||||||
|
color: cfg.theme.colors[colorScheme].gray,
|
||||||
|
gap: "1rem",
|
||||||
|
fontSize: "1.5rem",
|
||||||
|
fontFamily: fonts[1].name,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Li.map((item, index) => {
|
||||||
|
if (item) {
|
||||||
|
return <li key={index}>{item}</li>
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
color: cfg.theme.colors[colorScheme].light,
|
||||||
|
fontSize: "1.5rem",
|
||||||
|
overflow: "hidden",
|
||||||
|
marginRight: "8rem",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
display: "-webkit-box",
|
||||||
|
WebkitLineClamp: 7,
|
||||||
|
WebkitBoxOrient: "vertical",
|
||||||
|
lineClamp: 7,
|
||||||
|
fontFamily: fonts[1].name,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
19
docs/plugins/Favicon.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
title: Favicon
|
||||||
|
tags:
|
||||||
|
- plugin/emitter
|
||||||
|
---
|
||||||
|
|
||||||
|
This plugin emits a `favicon.ico` into the `public` folder. It creates the favicon from `icon.png` located in the `quartz/static` folder.
|
||||||
|
The plugin resizes `icon.png` to 48x48px to make it as small as possible.
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
> For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page.
|
||||||
|
|
||||||
|
This plugin has no configuration options.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
- Category: Emitter
|
||||||
|
- Function name: `Plugin.Favicon()`.
|
||||||
|
- Source: [`quartz/plugins/emitters/favicon.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/favicon.ts).
|
@ -17,6 +17,54 @@ This plugin accepts the following configuration options:
|
|||||||
> [!warning]
|
> [!warning]
|
||||||
> This plugin must not be removed, otherwise Quartz will break.
|
> This plugin must not be removed, otherwise Quartz will break.
|
||||||
|
|
||||||
|
## List
|
||||||
|
|
||||||
|
Quartz supports the following frontmatter:
|
||||||
|
|
||||||
|
- title
|
||||||
|
- `title`
|
||||||
|
- description
|
||||||
|
- `description`
|
||||||
|
- permalink
|
||||||
|
- `permalink`
|
||||||
|
- comments
|
||||||
|
- `comments`
|
||||||
|
- lang
|
||||||
|
- `lang`
|
||||||
|
- publish
|
||||||
|
- `publish`
|
||||||
|
- draft
|
||||||
|
- `draft`
|
||||||
|
- enableToc
|
||||||
|
- `enableToc`
|
||||||
|
- tags
|
||||||
|
- `tags`
|
||||||
|
- `tag`
|
||||||
|
- aliases
|
||||||
|
- `aliases`
|
||||||
|
- `alias`
|
||||||
|
- cssclasses
|
||||||
|
- `cssclasses`
|
||||||
|
- `cssclass`
|
||||||
|
- socialDescription
|
||||||
|
- `socialDescription`
|
||||||
|
- socialImage
|
||||||
|
- `socialImage`
|
||||||
|
- `image`
|
||||||
|
- `cover`
|
||||||
|
- created
|
||||||
|
- `created`
|
||||||
|
- `date`
|
||||||
|
- modified
|
||||||
|
- `modified`
|
||||||
|
- `lastmod`
|
||||||
|
- `updated`
|
||||||
|
- `last-modified`
|
||||||
|
- published
|
||||||
|
- `published`
|
||||||
|
- `publishDate`
|
||||||
|
- `date`
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
- Category: Transformer
|
- Category: Transformer
|
||||||
|
@ -11,9 +11,13 @@ This plugin adds LaTeX support to Quartz. See [[features/Latex|Latex]] for more
|
|||||||
|
|
||||||
This plugin accepts the following configuration options:
|
This plugin accepts the following configuration options:
|
||||||
|
|
||||||
- `renderEngine`: the engine to use to render LaTeX equations. Can be `"katex"` for [KaTeX](https://katex.org/) or `"mathjax"` for [MathJax](https://www.mathjax.org/) [SVG rendering](https://docs.mathjax.org/en/latest/output/svg.html). Defaults to KaTeX.
|
- `renderEngine`: the engine to use to render LaTeX equations. Can be `"katex"` for [KaTeX](https://katex.org/), `"mathjax"` for [MathJax](https://www.mathjax.org/) [SVG rendering](https://docs.mathjax.org/en/latest/output/svg.html), or `"typst"` for [Typst](https://typst.app/) (a new way to compose LaTeX equation). Defaults to KaTeX.
|
||||||
- `customMacros`: custom macros for all LaTeX blocks. It takes the form of a key-value pair where the key is a new command name and the value is the expansion of the macro. For example: `{"\\R": "\\mathbb{R}"}`
|
- `customMacros`: custom macros for all LaTeX blocks. It takes the form of a key-value pair where the key is a new command name and the value is the expansion of the macro. For example: `{"\\R": "\\mathbb{R}"}`
|
||||||
|
|
||||||
|
> [!note] Typst support
|
||||||
|
>
|
||||||
|
> Currently, typst doesn't support inline-math
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
- Category: Transformer
|
- Category: Transformer
|
||||||
|
@ -31,4 +31,4 @@ This plugin accepts the following configuration options:
|
|||||||
|
|
||||||
- Category: Transformer
|
- Category: Transformer
|
||||||
- Function name: `Plugin.ObsidianFlavoredMarkdown()`.
|
- Function name: `Plugin.ObsidianFlavoredMarkdown()`.
|
||||||
- Source: [`quartz/plugins/transformers/toc.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/toc.ts).
|
- Source: [`quartz/plugins/transformers/ofm.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/ofm.ts)
|
||||||
|
26
docs/plugins/RoamFlavoredMarkdown.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
title: RoamFlavoredMarkdown
|
||||||
|
tags:
|
||||||
|
- plugin/transformer
|
||||||
|
---
|
||||||
|
|
||||||
|
This plugin provides support for [Roam Research](https://roamresearch.com) compatibility. See [[Roam Research Compatibility]] for more information.
|
||||||
|
|
||||||
|
> [!note]
|
||||||
|
> For information on how to add, remove or configure plugins, see the [[Configuration#Plugins|Configuration]] page.
|
||||||
|
|
||||||
|
This plugin accepts the following configuration options:
|
||||||
|
|
||||||
|
- `orComponent`: If `true` (default), converts Roam `{{ or:ONE|TWO|THREE }}` shortcodes into HTML Dropdown options.
|
||||||
|
- `TODOComponent`: If `true` (default), converts Roam `{{[[TODO]]}}` shortcodes into HTML check boxes.
|
||||||
|
- `DONEComponent`: If `true` (default), converts Roam `{{[[DONE]]}}` shortcodes into checked HTML check boxes.
|
||||||
|
- `videoComponent`: If `true` (default), converts Roam `{{[[video]]:URL}}` shortcodes into embeded HTML video.
|
||||||
|
- `audioComponent`: If `true` (default), converts Roam `{{[[audio]]:URL}}` shortcodes into embeded HTML audio.
|
||||||
|
- `pdfComponent`: If `true` (default), converts Roam `{{[[pdf]]:URL}}` shortcodes into embeded HTML PDF viewer.
|
||||||
|
- `blockquoteComponent`: If `true` (default), converts Roam `{{[[>]]}}` shortcodes into Quartz blockquotes.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
- Category: Transformer
|
||||||
|
- Function name: `Plugin.RoamFlavoredMarkdown()`.
|
||||||
|
- Source: [`quartz/plugins/transformers/roam.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/roam.ts).
|
@ -34,6 +34,13 @@ npx quartz sync --no-pull
|
|||||||
> [!warning]- `fatal: --[no-]autostash option is only valid with --rebase`
|
> [!warning]- `fatal: --[no-]autostash option is only valid with --rebase`
|
||||||
> You may have an outdated version of `git`. Updating `git` should fix this issue.
|
> You may have an outdated version of `git`. Updating `git` should fix this issue.
|
||||||
|
|
||||||
|
> [!warning]- `fatal: The remote end hung up unexpectedly`
|
||||||
|
> It might be due to Git's default buffer size. You can fix it by increasing the buffer with this command:
|
||||||
|
>
|
||||||
|
> ```bash
|
||||||
|
> git config http.postBuffer 524288000
|
||||||
|
> ```
|
||||||
|
|
||||||
In future updates, you can simply run `npx quartz sync` every time you want to push updates to your repository.
|
In future updates, you can simply run `npx quartz sync` every time you want to push updates to your repository.
|
||||||
|
|
||||||
> [!hint] Flags and options
|
> [!hint] Flags and options
|
||||||
|
@ -9,6 +9,7 @@ Want to see what Quartz can do? Here are some cool community gardens:
|
|||||||
- [Socratica Toolbox](https://toolbox.socratica.info/)
|
- [Socratica Toolbox](https://toolbox.socratica.info/)
|
||||||
- [Morrowind Modding Wiki](https://morrowind-modding.github.io/)
|
- [Morrowind Modding Wiki](https://morrowind-modding.github.io/)
|
||||||
- [Aaron Pham's Garden](https://aarnphm.xyz/)
|
- [Aaron Pham's Garden](https://aarnphm.xyz/)
|
||||||
|
- [The Pond](https://turntrout.com/welcome)
|
||||||
- [Pelayo Arbues' Notes](https://pelayoarbues.com/)
|
- [Pelayo Arbues' Notes](https://pelayoarbues.com/)
|
||||||
- [Stanford CME 302 Numerical Linear Algebra](https://ericdarve.github.io/NLA/)
|
- [Stanford CME 302 Numerical Linear Algebra](https://ericdarve.github.io/NLA/)
|
||||||
- [A Pattern Language - Christopher Alexander (Architecture)](https://patternlanguage.cc/)
|
- [A Pattern Language - Christopher Alexander (Architecture)](https://patternlanguage.cc/)
|
||||||
@ -20,12 +21,14 @@ Want to see what Quartz can do? Here are some cool community gardens:
|
|||||||
- [Sideny's 3D Artist's Handbook](https://sidney-eliot.github.io/3d-artists-handbook/)
|
- [Sideny's 3D Artist's Handbook](https://sidney-eliot.github.io/3d-artists-handbook/)
|
||||||
- [Brandon Boswell's Garden](https://brandonkboswell.com)
|
- [Brandon Boswell's Garden](https://brandonkboswell.com)
|
||||||
- [Scaling Synthesis - A hypertext research notebook](https://scalingsynthesis.com/)
|
- [Scaling Synthesis - A hypertext research notebook](https://scalingsynthesis.com/)
|
||||||
|
- [Simon's Second Brain: Crafted, Curated, Connected, Compounded](https://brain.ssp.sh/)
|
||||||
|
- [Data Engineering Vault: A Second Brain Knowledge Network](https://vault.ssp.sh/)
|
||||||
- [Data Dictionary 🧠](https://glossary.airbyte.com/)
|
- [Data Dictionary 🧠](https://glossary.airbyte.com/)
|
||||||
- [sspaeti.com's Second Brain](https://brain.sspaeti.com/)
|
|
||||||
- [🪴Aster's notebook](https://notes.asterhu.com)
|
- [🪴Aster's notebook](https://notes.asterhu.com)
|
||||||
- [Gatekeeper Wiki](https://www.gatekeeper.wiki)
|
- [Gatekeeper Wiki](https://www.gatekeeper.wiki)
|
||||||
- [Ellie's Notes](https://ellie.wtf)
|
- [Ellie's Notes](https://ellie.wtf)
|
||||||
- [🥷🏻🌳🍃 Computer Science & Thinkering Garden](https://notes.yxy.ninja)
|
- [🥷🏻🌳🍃 Computer Science & Thinkering Garden](https://notes.yxy.ninja)
|
||||||
- [Eledah's Crystalline](https://blog.eledah.ir/)
|
- [Eledah's Crystalline](https://blog.eledah.ir/)
|
||||||
|
- [🌓 Projects & Privacy - FOSS, tech, law](https://be-far.com)
|
||||||
If you want to see your own on here, submit a [Pull Request adding yourself to this file](https://github.com/jackyzha0/quartz/blob/v4/docs/showcase.md)!
|
- [Zen Browser Docs](https://docs.zen-browser.app)
|
||||||
|
- [🪴8cat life](https://8cat.life)
|
||||||
|
3
index.d.ts
vendored
@ -5,8 +5,11 @@ declare module "*.scss" {
|
|||||||
|
|
||||||
// dom custom event
|
// dom custom event
|
||||||
interface CustomEventMap {
|
interface CustomEventMap {
|
||||||
|
prenav: CustomEvent<{}>
|
||||||
nav: CustomEvent<{ url: FullSlug }>
|
nav: CustomEvent<{ url: FullSlug }>
|
||||||
themechange: CustomEvent<{ theme: "light" | "dark" }>
|
themechange: CustomEvent<{ theme: "light" | "dark" }>
|
||||||
|
readermodechange: CustomEvent<{ mode: "on" | "off" }>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContentIndex = Record<FullSlug, ContentDetails>
|
||||||
declare const fetchData: Promise<ContentIndex>
|
declare const fetchData: Promise<ContentIndex>
|
||||||
|
3454
package-lock.json
generated
81
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "@jackyzha0/quartz",
|
"name": "@jackyzha0/quartz",
|
||||||
"description": "🌱 publish your digital garden and notes as a website",
|
"description": "🌱 publish your digital garden and notes as a website",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "4.3.1",
|
"version": "4.5.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "jackyzha0 <j.zhao2k19@gmail.com>",
|
"author": "jackyzha0 <j.zhao2k19@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -16,12 +16,12 @@
|
|||||||
"docs": "npx quartz build --serve -d docs",
|
"docs": "npx quartz build --serve -d docs",
|
||||||
"check": "tsc --noEmit && npx prettier . --check",
|
"check": "tsc --noEmit && npx prettier . --check",
|
||||||
"format": "npx prettier . --write",
|
"format": "npx prettier . --write",
|
||||||
"test": "tsx ./quartz/util/path.test.ts && tsx ./quartz/depgraph.test.ts",
|
"test": "tsx --test",
|
||||||
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
|
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"npm": ">=9.3.1",
|
"npm": ">=9.3.1",
|
||||||
"node": "20 || >=22"
|
"node": ">=20"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"site generator",
|
"site generator",
|
||||||
@ -35,78 +35,83 @@
|
|||||||
"quartz": "./quartz/bootstrap-cli.mjs"
|
"quartz": "./quartz/bootstrap-cli.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@clack/prompts": "^0.7.0",
|
"@clack/prompts": "^0.10.1",
|
||||||
"@floating-ui/dom": "^1.6.10",
|
"@floating-ui/dom": "^1.7.0",
|
||||||
"@napi-rs/simple-git": "0.1.17",
|
"@myriaddreamin/rehype-typst": "^0.6.0",
|
||||||
|
"@napi-rs/simple-git": "0.1.19",
|
||||||
"@tweenjs/tween.js": "^25.0.0",
|
"@tweenjs/tween.js": "^25.0.0",
|
||||||
|
"@webgpu/types": "^0.1.60",
|
||||||
|
"ansi-truncate": "^1.2.0",
|
||||||
"async-mutex": "^0.5.0",
|
"async-mutex": "^0.5.0",
|
||||||
"chalk": "^5.3.0",
|
"chalk": "^5.4.1",
|
||||||
"chokidar": "^3.6.0",
|
"chokidar": "^4.0.3",
|
||||||
"cli-spinner": "^0.2.10",
|
"cli-spinner": "^0.2.10",
|
||||||
"d3": "^7.9.0",
|
"d3": "^7.9.0",
|
||||||
"esbuild-sass-plugin": "^2.16.1",
|
"esbuild-sass-plugin": "^3.3.1",
|
||||||
"flexsearch": "0.7.43",
|
"flexsearch": "0.7.43",
|
||||||
"github-slugger": "^2.0.0",
|
"github-slugger": "^2.0.0",
|
||||||
"globby": "^14.0.2",
|
"globby": "^14.1.0",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"hast-util-to-html": "^9.0.1",
|
"hast-util-to-html": "^9.0.5",
|
||||||
"hast-util-to-jsx-runtime": "^2.3.0",
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
||||||
"hast-util-to-string": "^3.0.0",
|
"hast-util-to-string": "^3.0.1",
|
||||||
"is-absolute-url": "^4.0.1",
|
"is-absolute-url": "^4.0.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"lightningcss": "^1.26.0",
|
"lightningcss": "^1.29.3",
|
||||||
"mdast-util-find-and-replace": "^3.0.1",
|
"mdast-util-find-and-replace": "^3.0.2",
|
||||||
"mdast-util-to-hast": "^13.2.0",
|
"mdast-util-to-hast": "^13.2.0",
|
||||||
"mdast-util-to-string": "^4.0.0",
|
"mdast-util-to-string": "^4.0.0",
|
||||||
"micromorph": "^0.4.5",
|
"micromorph": "^0.4.5",
|
||||||
"pixi.js": "^8.3.3",
|
"minimatch": "^10.0.1",
|
||||||
"preact": "^10.23.2",
|
"pixi.js": "^8.9.2",
|
||||||
"preact-render-to-string": "^6.5.9",
|
"preact": "^10.26.5",
|
||||||
"pretty-bytes": "^6.1.1",
|
"preact-render-to-string": "^6.5.13",
|
||||||
|
"pretty-bytes": "^7.0.0",
|
||||||
"pretty-time": "^1.1.0",
|
"pretty-time": "^1.1.0",
|
||||||
"reading-time": "^1.5.0",
|
"reading-time": "^1.5.0",
|
||||||
"rehype-autolink-headings": "^7.1.0",
|
"rehype-autolink-headings": "^7.1.0",
|
||||||
"rehype-citation": "^2.1.1",
|
"rehype-citation": "^2.3.1",
|
||||||
"rehype-katex": "^7.0.1",
|
"rehype-katex": "^7.0.1",
|
||||||
"rehype-mathjax": "^6.0.0",
|
"rehype-mathjax": "^7.1.0",
|
||||||
"rehype-pretty-code": "^0.13.2",
|
"rehype-pretty-code": "^0.14.1",
|
||||||
"rehype-raw": "^7.0.0",
|
"rehype-raw": "^7.0.0",
|
||||||
"rehype-slug": "^6.0.0",
|
"rehype-slug": "^6.0.0",
|
||||||
"remark": "^15.0.1",
|
"remark": "^15.0.1",
|
||||||
"remark-breaks": "^4.0.0",
|
"remark-breaks": "^4.0.0",
|
||||||
"remark-frontmatter": "^5.0.0",
|
"remark-frontmatter": "^5.0.0",
|
||||||
"remark-gfm": "^4.0.0",
|
"remark-gfm": "^4.0.1",
|
||||||
"remark-math": "^6.0.0",
|
"remark-math": "^6.0.0",
|
||||||
"remark-parse": "^11.0.0",
|
"remark-parse": "^11.0.0",
|
||||||
"remark-rehype": "^11.1.0",
|
"remark-rehype": "^11.1.2",
|
||||||
"remark-smartypants": "^3.0.2",
|
"remark-smartypants": "^3.0.2",
|
||||||
"rfdc": "^1.4.1",
|
"rfdc": "^1.4.1",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"serve-handler": "^6.1.5",
|
"satori": "^0.12.2",
|
||||||
"shiki": "^1.12.1",
|
"serve-handler": "^6.1.6",
|
||||||
|
"sharp": "^0.34.1",
|
||||||
|
"shiki": "^1.26.2",
|
||||||
"source-map-support": "^0.5.21",
|
"source-map-support": "^0.5.21",
|
||||||
"to-vfile": "^8.0.0",
|
"to-vfile": "^8.0.0",
|
||||||
"toml": "^3.0.0",
|
"toml": "^3.0.0",
|
||||||
"unified": "^11.0.4",
|
"unified": "^11.0.5",
|
||||||
"unist-util-visit": "^5.0.0",
|
"unist-util-visit": "^5.0.0",
|
||||||
"vfile": "^6.0.2",
|
"vfile": "^6.0.3",
|
||||||
"workerpool": "^9.1.3",
|
"workerpool": "^9.2.0",
|
||||||
"ws": "^8.18.0",
|
"ws": "^8.18.2",
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cli-spinner": "^0.2.3",
|
|
||||||
"@types/d3": "^7.4.3",
|
"@types/d3": "^7.4.3",
|
||||||
"@types/hast": "^3.0.4",
|
"@types/hast": "^3.0.4",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@types/node": "^22.1.0",
|
"@types/node": "^22.15.7",
|
||||||
"@types/pretty-time": "^1.1.5",
|
"@types/pretty-time": "^1.1.5",
|
||||||
"@types/source-map-support": "^0.5.10",
|
"@types/source-map-support": "^0.5.10",
|
||||||
"@types/ws": "^8.5.12",
|
"@types/ws": "^8.18.1",
|
||||||
"@types/yargs": "^17.0.32",
|
"@types/yargs": "^17.0.33",
|
||||||
"esbuild": "^0.19.9",
|
"esbuild": "^0.25.3",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.5.3",
|
||||||
"tsx": "^4.17.0",
|
"tsx": "^4.19.4",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,14 @@ import { QuartzConfig } from "./quartz/cfg"
|
|||||||
import * as Plugin from "./quartz/plugins"
|
import * as Plugin from "./quartz/plugins"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quartz 4.0 Configuration
|
* Quartz 4 Configuration
|
||||||
*
|
*
|
||||||
* See https://quartz.jzhao.xyz/configuration for more information.
|
* See https://quartz.jzhao.xyz/configuration for more information.
|
||||||
*/
|
*/
|
||||||
const config: QuartzConfig = {
|
const config: QuartzConfig = {
|
||||||
configuration: {
|
configuration: {
|
||||||
pageTitle: "🪴 Quartz 4.0",
|
pageTitle: "Quartz 4",
|
||||||
|
pageTitleSuffix: "",
|
||||||
enableSPA: true,
|
enableSPA: true,
|
||||||
enablePopovers: true,
|
enablePopovers: true,
|
||||||
analytics: {
|
analytics: {
|
||||||
@ -17,7 +18,7 @@ const config: QuartzConfig = {
|
|||||||
locale: "en-US",
|
locale: "en-US",
|
||||||
baseUrl: "quartz.jzhao.xyz",
|
baseUrl: "quartz.jzhao.xyz",
|
||||||
ignorePatterns: ["private", "templates", ".obsidian"],
|
ignorePatterns: ["private", "templates", ".obsidian"],
|
||||||
defaultDateType: "created",
|
defaultDateType: "modified",
|
||||||
theme: {
|
theme: {
|
||||||
fontOrigin: "googleFonts",
|
fontOrigin: "googleFonts",
|
||||||
cdnCaching: true,
|
cdnCaching: true,
|
||||||
@ -56,7 +57,7 @@ const config: QuartzConfig = {
|
|||||||
transformers: [
|
transformers: [
|
||||||
Plugin.FrontMatter(),
|
Plugin.FrontMatter(),
|
||||||
Plugin.CreatedModifiedDate({
|
Plugin.CreatedModifiedDate({
|
||||||
priority: ["frontmatter", "filesystem"],
|
priority: ["frontmatter", "git", "filesystem"],
|
||||||
}),
|
}),
|
||||||
Plugin.SyntaxHighlighting({
|
Plugin.SyntaxHighlighting({
|
||||||
theme: {
|
theme: {
|
||||||
@ -85,7 +86,10 @@ const config: QuartzConfig = {
|
|||||||
}),
|
}),
|
||||||
Plugin.Assets(),
|
Plugin.Assets(),
|
||||||
Plugin.Static(),
|
Plugin.Static(),
|
||||||
|
Plugin.Favicon(),
|
||||||
Plugin.NotFoundPage(),
|
Plugin.NotFoundPage(),
|
||||||
|
// Comment out CustomOgImages to speed up build time
|
||||||
|
Plugin.CustomOgImages(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,10 @@ export const sharedPageComponents: SharedLayout = {
|
|||||||
// components for pages that display a single page (e.g. a single note)
|
// components for pages that display a single page (e.g. a single note)
|
||||||
export const defaultContentPageLayout: PageLayout = {
|
export const defaultContentPageLayout: PageLayout = {
|
||||||
beforeBody: [
|
beforeBody: [
|
||||||
Component.Breadcrumbs(),
|
Component.ConditionalRender({
|
||||||
|
component: Component.Breadcrumbs(),
|
||||||
|
condition: (page) => page.fileData.slug !== "index",
|
||||||
|
}),
|
||||||
Component.ArticleTitle(),
|
Component.ArticleTitle(),
|
||||||
Component.ContentMeta(),
|
Component.ContentMeta(),
|
||||||
Component.TagList(),
|
Component.TagList(),
|
||||||
@ -25,9 +28,17 @@ export const defaultContentPageLayout: PageLayout = {
|
|||||||
left: [
|
left: [
|
||||||
Component.PageTitle(),
|
Component.PageTitle(),
|
||||||
Component.MobileOnly(Component.Spacer()),
|
Component.MobileOnly(Component.Spacer()),
|
||||||
Component.Search(),
|
Component.Flex({
|
||||||
Component.Darkmode(),
|
components: [
|
||||||
Component.DesktopOnly(Component.Explorer()),
|
{
|
||||||
|
Component: Component.Search(),
|
||||||
|
grow: true,
|
||||||
|
},
|
||||||
|
{ Component: Component.Darkmode() },
|
||||||
|
{ Component: Component.ReaderMode() },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
Component.Explorer(),
|
||||||
],
|
],
|
||||||
right: [
|
right: [
|
||||||
Component.Graph(),
|
Component.Graph(),
|
||||||
@ -42,9 +53,16 @@ export const defaultListPageLayout: PageLayout = {
|
|||||||
left: [
|
left: [
|
||||||
Component.PageTitle(),
|
Component.PageTitle(),
|
||||||
Component.MobileOnly(Component.Spacer()),
|
Component.MobileOnly(Component.Spacer()),
|
||||||
Component.Search(),
|
Component.Flex({
|
||||||
Component.Darkmode(),
|
components: [
|
||||||
Component.DesktopOnly(Component.Explorer()),
|
{
|
||||||
|
Component: Component.Search(),
|
||||||
|
grow: true,
|
||||||
|
},
|
||||||
|
{ Component: Component.Darkmode() },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
Component.Explorer(),
|
||||||
],
|
],
|
||||||
right: [],
|
right: [],
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env -S node --no-deprecation
|
||||||
import yargs from "yargs"
|
import yargs from "yargs"
|
||||||
import { hideBin } from "yargs/helpers"
|
import { hideBin } from "yargs/helpers"
|
||||||
import {
|
import {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import workerpool from "workerpool"
|
import workerpool from "workerpool"
|
||||||
const cacheFile = "./.quartz-cache/transpiled-worker.mjs"
|
const cacheFile = "./.quartz-cache/transpiled-worker.mjs"
|
||||||
const { parseFiles } = await import(cacheFile)
|
const { parseMarkdown, processHtml } = await import(cacheFile)
|
||||||
workerpool.worker({
|
workerpool.worker({
|
||||||
parseFiles,
|
parseMarkdown,
|
||||||
|
processHtml,
|
||||||
})
|
})
|
||||||
|
440
quartz/build.ts
@ -9,7 +9,7 @@ import { parseMarkdown } from "./processors/parse"
|
|||||||
import { filterContent } from "./processors/filter"
|
import { filterContent } from "./processors/filter"
|
||||||
import { emitContent } from "./processors/emit"
|
import { emitContent } from "./processors/emit"
|
||||||
import cfg from "../quartz.config"
|
import cfg from "../quartz.config"
|
||||||
import { FilePath, FullSlug, joinSegments, slugifyFilePath } from "./util/path"
|
import { FilePath, joinSegments, slugifyFilePath } from "./util/path"
|
||||||
import chokidar from "chokidar"
|
import chokidar from "chokidar"
|
||||||
import { ProcessedContent } from "./plugins/vfile"
|
import { ProcessedContent } from "./plugins/vfile"
|
||||||
import { Argv, BuildCtx } from "./util/ctx"
|
import { Argv, BuildCtx } from "./util/ctx"
|
||||||
@ -17,37 +17,39 @@ import { glob, toPosixPath } from "./util/glob"
|
|||||||
import { trace } from "./util/trace"
|
import { trace } from "./util/trace"
|
||||||
import { options } from "./util/sourcemap"
|
import { options } from "./util/sourcemap"
|
||||||
import { Mutex } from "async-mutex"
|
import { Mutex } from "async-mutex"
|
||||||
import DepGraph from "./depgraph"
|
|
||||||
import { getStaticResourcesFromPlugins } from "./plugins"
|
import { getStaticResourcesFromPlugins } from "./plugins"
|
||||||
|
import { randomIdNonSecure } from "./util/random"
|
||||||
|
import { ChangeEvent } from "./plugins/types"
|
||||||
|
import { minimatch } from "minimatch"
|
||||||
|
|
||||||
type Dependencies = Record<string, DepGraph<FilePath> | null>
|
type ContentMap = Map<
|
||||||
|
FilePath,
|
||||||
|
| {
|
||||||
|
type: "markdown"
|
||||||
|
content: ProcessedContent
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: "other"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
|
||||||
type BuildData = {
|
type BuildData = {
|
||||||
ctx: BuildCtx
|
ctx: BuildCtx
|
||||||
ignored: GlobbyFilterFunction
|
ignored: GlobbyFilterFunction
|
||||||
mut: Mutex
|
mut: Mutex
|
||||||
initialSlugs: FullSlug[]
|
contentMap: ContentMap
|
||||||
// TODO merge contentMap and trackedAssets
|
changesSinceLastBuild: Record<FilePath, ChangeEvent["type"]>
|
||||||
contentMap: Map<FilePath, ProcessedContent>
|
|
||||||
trackedAssets: Set<FilePath>
|
|
||||||
toRebuild: Set<FilePath>
|
|
||||||
toRemove: Set<FilePath>
|
|
||||||
lastBuildMs: number
|
lastBuildMs: number
|
||||||
dependencies: Dependencies
|
|
||||||
}
|
|
||||||
|
|
||||||
type FileEvent = "add" | "change" | "delete"
|
|
||||||
|
|
||||||
function newBuildId() {
|
|
||||||
return new Date().toISOString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) {
|
async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) {
|
||||||
const ctx: BuildCtx = {
|
const ctx: BuildCtx = {
|
||||||
buildId: newBuildId(),
|
buildId: randomIdNonSecure(),
|
||||||
argv,
|
argv,
|
||||||
cfg,
|
cfg,
|
||||||
allSlugs: [],
|
allSlugs: [],
|
||||||
|
allFiles: [],
|
||||||
|
incremental: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
const perf = new PerfTimer()
|
const perf = new PerfTimer()
|
||||||
@ -70,64 +72,70 @@ async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) {
|
|||||||
|
|
||||||
perf.addEvent("glob")
|
perf.addEvent("glob")
|
||||||
const allFiles = await glob("**/*.*", argv.directory, cfg.configuration.ignorePatterns)
|
const allFiles = await glob("**/*.*", argv.directory, cfg.configuration.ignorePatterns)
|
||||||
const fps = allFiles.filter((fp) => fp.endsWith(".md")).sort()
|
const markdownPaths = allFiles.filter((fp) => fp.endsWith(".md")).sort()
|
||||||
console.log(
|
console.log(
|
||||||
`Found ${fps.length} input files from \`${argv.directory}\` in ${perf.timeSince("glob")}`,
|
`Found ${markdownPaths.length} input files from \`${argv.directory}\` in ${perf.timeSince("glob")}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
const filePaths = fps.map((fp) => joinSegments(argv.directory, fp) as FilePath)
|
const filePaths = markdownPaths.map((fp) => joinSegments(argv.directory, fp) as FilePath)
|
||||||
|
ctx.allFiles = allFiles
|
||||||
ctx.allSlugs = allFiles.map((fp) => slugifyFilePath(fp as FilePath))
|
ctx.allSlugs = allFiles.map((fp) => slugifyFilePath(fp as FilePath))
|
||||||
|
|
||||||
const parsedFiles = await parseMarkdown(ctx, filePaths)
|
const parsedFiles = await parseMarkdown(ctx, filePaths)
|
||||||
const filteredContent = filterContent(ctx, parsedFiles)
|
const filteredContent = filterContent(ctx, parsedFiles)
|
||||||
|
|
||||||
const dependencies: Record<string, DepGraph<FilePath> | null> = {}
|
|
||||||
|
|
||||||
// Only build dependency graphs if we're doing a fast rebuild
|
|
||||||
if (argv.fastRebuild) {
|
|
||||||
const staticResources = getStaticResourcesFromPlugins(ctx)
|
|
||||||
for (const emitter of cfg.plugins.emitters) {
|
|
||||||
dependencies[emitter.name] =
|
|
||||||
(await emitter.getDependencyGraph?.(ctx, filteredContent, staticResources)) ?? null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await emitContent(ctx, filteredContent)
|
await emitContent(ctx, filteredContent)
|
||||||
console.log(chalk.green(`Done processing ${fps.length} files in ${perf.timeSince()}`))
|
console.log(chalk.green(`Done processing ${markdownPaths.length} files in ${perf.timeSince()}`))
|
||||||
release()
|
release()
|
||||||
|
|
||||||
if (argv.serve) {
|
if (argv.watch) {
|
||||||
return startServing(ctx, mut, parsedFiles, clientRefresh, dependencies)
|
ctx.incremental = true
|
||||||
|
return startWatching(ctx, mut, parsedFiles, clientRefresh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup watcher for rebuilds
|
// setup watcher for rebuilds
|
||||||
async function startServing(
|
async function startWatching(
|
||||||
ctx: BuildCtx,
|
ctx: BuildCtx,
|
||||||
mut: Mutex,
|
mut: Mutex,
|
||||||
initialContent: ProcessedContent[],
|
initialContent: ProcessedContent[],
|
||||||
clientRefresh: () => void,
|
clientRefresh: () => void,
|
||||||
dependencies: Dependencies, // emitter name: dep graph
|
|
||||||
) {
|
) {
|
||||||
const { argv } = ctx
|
const { argv, allFiles } = ctx
|
||||||
|
|
||||||
// cache file parse results
|
const contentMap: ContentMap = new Map()
|
||||||
const contentMap = new Map<FilePath, ProcessedContent>()
|
for (const filePath of allFiles) {
|
||||||
for (const content of initialContent) {
|
contentMap.set(filePath, {
|
||||||
const [_tree, vfile] = content
|
type: "other",
|
||||||
contentMap.set(vfile.data.filePath!, content)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const content of initialContent) {
|
||||||
|
const [_tree, vfile] = content
|
||||||
|
contentMap.set(vfile.data.relativePath!, {
|
||||||
|
type: "markdown",
|
||||||
|
content,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const gitIgnoredMatcher = await isGitIgnored()
|
||||||
const buildData: BuildData = {
|
const buildData: BuildData = {
|
||||||
ctx,
|
ctx,
|
||||||
mut,
|
mut,
|
||||||
dependencies,
|
|
||||||
contentMap,
|
contentMap,
|
||||||
ignored: await isGitIgnored(),
|
ignored: (path) => {
|
||||||
initialSlugs: ctx.allSlugs,
|
if (gitIgnoredMatcher(path)) return true
|
||||||
toRebuild: new Set<FilePath>(),
|
const pathStr = path.toString()
|
||||||
toRemove: new Set<FilePath>(),
|
for (const pattern of cfg.configuration.ignorePatterns) {
|
||||||
trackedAssets: new Set<FilePath>(),
|
if (minimatch(pathStr, pattern)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
|
||||||
|
changesSinceLastBuild: {},
|
||||||
lastBuildMs: 0,
|
lastBuildMs: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,278 +145,146 @@ async function startServing(
|
|||||||
ignoreInitial: true,
|
ignoreInitial: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const buildFromEntry = argv.fastRebuild ? partialRebuildFromEntrypoint : rebuildFromEntrypoint
|
const changes: ChangeEvent[] = []
|
||||||
watcher
|
watcher
|
||||||
.on("add", (fp) => buildFromEntry(fp, "add", clientRefresh, buildData))
|
.on("add", (fp) => {
|
||||||
.on("change", (fp) => buildFromEntry(fp, "change", clientRefresh, buildData))
|
if (buildData.ignored(fp)) return
|
||||||
.on("unlink", (fp) => buildFromEntry(fp, "delete", clientRefresh, buildData))
|
changes.push({ path: fp as FilePath, type: "add" })
|
||||||
|
void rebuild(changes, clientRefresh, buildData)
|
||||||
|
})
|
||||||
|
.on("change", (fp) => {
|
||||||
|
if (buildData.ignored(fp)) return
|
||||||
|
changes.push({ path: fp as FilePath, type: "change" })
|
||||||
|
void rebuild(changes, clientRefresh, buildData)
|
||||||
|
})
|
||||||
|
.on("unlink", (fp) => {
|
||||||
|
if (buildData.ignored(fp)) return
|
||||||
|
changes.push({ path: fp as FilePath, type: "delete" })
|
||||||
|
void rebuild(changes, clientRefresh, buildData)
|
||||||
|
})
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
await watcher.close()
|
await watcher.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function partialRebuildFromEntrypoint(
|
async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildData: BuildData) {
|
||||||
filepath: string,
|
const { ctx, contentMap, mut, changesSinceLastBuild } = buildData
|
||||||
action: FileEvent,
|
|
||||||
clientRefresh: () => void,
|
|
||||||
buildData: BuildData, // note: this function mutates buildData
|
|
||||||
) {
|
|
||||||
const { ctx, ignored, dependencies, contentMap, mut, toRemove } = buildData
|
|
||||||
const { argv, cfg } = ctx
|
const { argv, cfg } = ctx
|
||||||
|
|
||||||
// don't do anything for gitignored files
|
const buildId = randomIdNonSecure()
|
||||||
if (ignored(filepath)) {
|
ctx.buildId = buildId
|
||||||
return
|
buildData.lastBuildMs = new Date().getTime()
|
||||||
}
|
const numChangesInBuild = changes.length
|
||||||
|
|
||||||
const buildStart = new Date().getTime()
|
|
||||||
buildData.lastBuildMs = buildStart
|
|
||||||
const release = await mut.acquire()
|
const release = await mut.acquire()
|
||||||
if (buildData.lastBuildMs > buildStart) {
|
|
||||||
|
// if there's another build after us, release and let them do it
|
||||||
|
if (ctx.buildId !== buildId) {
|
||||||
release()
|
release()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const perf = new PerfTimer()
|
const perf = new PerfTimer()
|
||||||
|
perf.addEvent("rebuild")
|
||||||
console.log(chalk.yellow("Detected change, rebuilding..."))
|
console.log(chalk.yellow("Detected change, rebuilding..."))
|
||||||
ctx.buildId = newBuildId()
|
|
||||||
|
|
||||||
// UPDATE DEP GRAPH
|
// update changesSinceLastBuild
|
||||||
const fp = joinSegments(argv.directory, toPosixPath(filepath)) as FilePath
|
for (const change of changes) {
|
||||||
|
changesSinceLastBuild[change.path] = change.type
|
||||||
|
}
|
||||||
|
|
||||||
const staticResources = getStaticResourcesFromPlugins(ctx)
|
const staticResources = getStaticResourcesFromPlugins(ctx)
|
||||||
let processedFiles: ProcessedContent[] = []
|
const pathsToParse: FilePath[] = []
|
||||||
|
for (const [fp, type] of Object.entries(changesSinceLastBuild)) {
|
||||||
switch (action) {
|
if (type === "delete" || path.extname(fp) !== ".md") continue
|
||||||
case "add":
|
const fullPath = joinSegments(argv.directory, toPosixPath(fp)) as FilePath
|
||||||
// add to cache when new file is added
|
pathsToParse.push(fullPath)
|
||||||
processedFiles = await parseMarkdown(ctx, [fp])
|
|
||||||
processedFiles.forEach(([tree, vfile]) => contentMap.set(vfile.data.filePath!, [tree, vfile]))
|
|
||||||
|
|
||||||
// update the dep graph by asking all emitters whether they depend on this file
|
|
||||||
for (const emitter of cfg.plugins.emitters) {
|
|
||||||
const emitterGraph =
|
|
||||||
(await emitter.getDependencyGraph?.(ctx, processedFiles, staticResources)) ?? null
|
|
||||||
|
|
||||||
if (emitterGraph) {
|
|
||||||
const existingGraph = dependencies[emitter.name]
|
|
||||||
if (existingGraph !== null) {
|
|
||||||
existingGraph.mergeGraph(emitterGraph)
|
|
||||||
} else {
|
|
||||||
// might be the first time we're adding a mardown file
|
|
||||||
dependencies[emitter.name] = emitterGraph
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "change":
|
|
||||||
// invalidate cache when file is changed
|
|
||||||
processedFiles = await parseMarkdown(ctx, [fp])
|
|
||||||
processedFiles.forEach(([tree, vfile]) => contentMap.set(vfile.data.filePath!, [tree, vfile]))
|
|
||||||
|
|
||||||
// only content files can have added/removed dependencies because of transclusions
|
|
||||||
if (path.extname(fp) === ".md") {
|
|
||||||
for (const emitter of cfg.plugins.emitters) {
|
|
||||||
// get new dependencies from all emitters for this file
|
|
||||||
const emitterGraph =
|
|
||||||
(await emitter.getDependencyGraph?.(ctx, processedFiles, staticResources)) ?? null
|
|
||||||
|
|
||||||
// only update the graph if the emitter plugin uses the changed file
|
|
||||||
// eg. Assets plugin ignores md files, so we skip updating the graph
|
|
||||||
if (emitterGraph?.hasNode(fp)) {
|
|
||||||
// merge the new dependencies into the dep graph
|
|
||||||
dependencies[emitter.name]?.updateIncomingEdgesForNode(emitterGraph, fp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case "delete":
|
|
||||||
toRemove.add(fp)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.verbose) {
|
const parsed = await parseMarkdown(ctx, pathsToParse)
|
||||||
console.log(`Updated dependency graphs in ${perf.timeSince()}`)
|
for (const content of parsed) {
|
||||||
|
contentMap.set(content[1].data.relativePath!, {
|
||||||
|
type: "markdown",
|
||||||
|
content,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// EMIT
|
// update state using changesSinceLastBuild
|
||||||
perf.addEvent("rebuild")
|
// we do this weird play of add => compute change events => remove
|
||||||
|
// so that partialEmitters can do appropriate cleanup based on the content of deleted files
|
||||||
|
for (const [file, change] of Object.entries(changesSinceLastBuild)) {
|
||||||
|
if (change === "delete") {
|
||||||
|
// universal delete case
|
||||||
|
contentMap.delete(file as FilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// manually track non-markdown files as processed files only
|
||||||
|
// contains markdown files
|
||||||
|
if (change === "add" && path.extname(file) !== ".md") {
|
||||||
|
contentMap.set(file as FilePath, {
|
||||||
|
type: "other",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const changeEvents: ChangeEvent[] = Object.entries(changesSinceLastBuild).map(([fp, type]) => {
|
||||||
|
const path = fp as FilePath
|
||||||
|
const processedContent = contentMap.get(path)
|
||||||
|
if (processedContent?.type === "markdown") {
|
||||||
|
const [_tree, file] = processedContent.content
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
path,
|
||||||
|
file,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
path,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// update allFiles and then allSlugs with the consistent view of content map
|
||||||
|
ctx.allFiles = Array.from(contentMap.keys())
|
||||||
|
ctx.allSlugs = ctx.allFiles.map((fp) => slugifyFilePath(fp as FilePath))
|
||||||
|
const processedFiles = Array.from(contentMap.values())
|
||||||
|
.filter((file) => file.type === "markdown")
|
||||||
|
.map((file) => file.content)
|
||||||
|
|
||||||
let emittedFiles = 0
|
let emittedFiles = 0
|
||||||
|
|
||||||
for (const emitter of cfg.plugins.emitters) {
|
for (const emitter of cfg.plugins.emitters) {
|
||||||
const depGraph = dependencies[emitter.name]
|
// Try to use partialEmit if available, otherwise assume the output is static
|
||||||
|
const emitFn = emitter.partialEmit ?? emitter.emit
|
||||||
// emitter hasn't defined a dependency graph. call it with all processed files
|
const emitted = await emitFn(ctx, processedFiles, staticResources, changeEvents)
|
||||||
if (depGraph === null) {
|
if (emitted === null) {
|
||||||
if (argv.verbose) {
|
|
||||||
console.log(
|
|
||||||
`Emitter ${emitter.name} doesn't define a dependency graph. Calling it with all files...`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = [...contentMap.values()].filter(
|
|
||||||
([_node, vfile]) => !toRemove.has(vfile.data.filePath!),
|
|
||||||
)
|
|
||||||
|
|
||||||
const emittedFps = await emitter.emit(ctx, files, staticResources)
|
|
||||||
|
|
||||||
if (ctx.argv.verbose) {
|
|
||||||
for (const file of emittedFps) {
|
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emittedFiles += emittedFps.length
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// only call the emitter if it uses this file
|
if (Symbol.asyncIterator in emitted) {
|
||||||
if (depGraph.hasNode(fp)) {
|
// Async generator case
|
||||||
// re-emit using all files that are needed for the downstream of this file
|
for await (const file of emitted) {
|
||||||
// eg. for ContentIndex, the dep graph could be:
|
emittedFiles++
|
||||||
// a.md --> contentIndex.json
|
if (ctx.argv.verbose) {
|
||||||
// b.md ------^
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
//
|
}
|
||||||
// if a.md changes, we need to re-emit contentIndex.json,
|
}
|
||||||
// and supply [a.md, b.md] to the emitter
|
} else {
|
||||||
const upstreams = [...depGraph.getLeafNodeAncestors(fp)] as FilePath[]
|
// Array case
|
||||||
|
emittedFiles += emitted.length
|
||||||
const upstreamContent = upstreams
|
if (ctx.argv.verbose) {
|
||||||
// filter out non-markdown files
|
for (const file of emitted) {
|
||||||
.filter((file) => contentMap.has(file))
|
|
||||||
// if file was deleted, don't give it to the emitter
|
|
||||||
.filter((file) => !toRemove.has(file))
|
|
||||||
.map((file) => contentMap.get(file)!)
|
|
||||||
|
|
||||||
const emittedFps = await emitter.emit(ctx, upstreamContent, staticResources)
|
|
||||||
|
|
||||||
if (ctx.argv.verbose) {
|
|
||||||
for (const file of emittedFps) {
|
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emittedFiles += emittedFps.length
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
||||||
|
|
||||||
// CLEANUP
|
|
||||||
const destinationsToDelete = new Set<FilePath>()
|
|
||||||
for (const file of toRemove) {
|
|
||||||
// remove from cache
|
|
||||||
contentMap.delete(file)
|
|
||||||
Object.values(dependencies).forEach((depGraph) => {
|
|
||||||
// remove the node from dependency graphs
|
|
||||||
depGraph?.removeNode(file)
|
|
||||||
// remove any orphan nodes. eg if a.md is deleted, a.html is orphaned and should be removed
|
|
||||||
const orphanNodes = depGraph?.removeOrphanNodes()
|
|
||||||
orphanNodes?.forEach((node) => {
|
|
||||||
// only delete files that are in the output directory
|
|
||||||
if (node.startsWith(argv.output)) {
|
|
||||||
destinationsToDelete.add(node)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
await rimraf([...destinationsToDelete])
|
|
||||||
|
|
||||||
console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
||||||
|
changes.splice(0, numChangesInBuild)
|
||||||
toRemove.clear()
|
|
||||||
release()
|
|
||||||
clientRefresh()
|
clientRefresh()
|
||||||
}
|
|
||||||
|
|
||||||
async function rebuildFromEntrypoint(
|
|
||||||
fp: string,
|
|
||||||
action: FileEvent,
|
|
||||||
clientRefresh: () => void,
|
|
||||||
buildData: BuildData, // note: this function mutates buildData
|
|
||||||
) {
|
|
||||||
const { ctx, ignored, mut, initialSlugs, contentMap, toRebuild, toRemove, trackedAssets } =
|
|
||||||
buildData
|
|
||||||
|
|
||||||
const { argv } = ctx
|
|
||||||
|
|
||||||
// don't do anything for gitignored files
|
|
||||||
if (ignored(fp)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// dont bother rebuilding for non-content files, just track and refresh
|
|
||||||
fp = toPosixPath(fp)
|
|
||||||
const filePath = joinSegments(argv.directory, fp) as FilePath
|
|
||||||
if (path.extname(fp) !== ".md") {
|
|
||||||
if (action === "add" || action === "change") {
|
|
||||||
trackedAssets.add(filePath)
|
|
||||||
} else if (action === "delete") {
|
|
||||||
trackedAssets.delete(filePath)
|
|
||||||
}
|
|
||||||
clientRefresh()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action === "add" || action === "change") {
|
|
||||||
toRebuild.add(filePath)
|
|
||||||
} else if (action === "delete") {
|
|
||||||
toRemove.add(filePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
const buildStart = new Date().getTime()
|
|
||||||
buildData.lastBuildMs = buildStart
|
|
||||||
const release = await mut.acquire()
|
|
||||||
|
|
||||||
// there's another build after us, release and let them do it
|
|
||||||
if (buildData.lastBuildMs > buildStart) {
|
|
||||||
release()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const perf = new PerfTimer()
|
|
||||||
console.log(chalk.yellow("Detected change, rebuilding..."))
|
|
||||||
ctx.buildId = newBuildId()
|
|
||||||
|
|
||||||
try {
|
|
||||||
const filesToRebuild = [...toRebuild].filter((fp) => !toRemove.has(fp))
|
|
||||||
const parsedContent = await parseMarkdown(ctx, filesToRebuild)
|
|
||||||
for (const content of parsedContent) {
|
|
||||||
const [_tree, vfile] = content
|
|
||||||
contentMap.set(vfile.data.filePath!, content)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const fp of toRemove) {
|
|
||||||
contentMap.delete(fp)
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedFiles = [...contentMap.values()]
|
|
||||||
const filteredContent = filterContent(ctx, parsedFiles)
|
|
||||||
|
|
||||||
// re-update slugs
|
|
||||||
const trackedSlugs = [...new Set([...contentMap.keys(), ...toRebuild, ...trackedAssets])]
|
|
||||||
.filter((fp) => !toRemove.has(fp))
|
|
||||||
.map((fp) => slugifyFilePath(path.posix.relative(argv.directory, fp) as FilePath))
|
|
||||||
|
|
||||||
ctx.allSlugs = [...new Set([...initialSlugs, ...trackedSlugs])]
|
|
||||||
|
|
||||||
// TODO: we can probably traverse the link graph to figure out what's safe to delete here
|
|
||||||
// instead of just deleting everything
|
|
||||||
await rimraf(path.join(argv.output, ".*"), { glob: true })
|
|
||||||
await emitContent(ctx, filteredContent)
|
|
||||||
console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
|
||||||
} catch (err) {
|
|
||||||
console.log(chalk.yellow(`Rebuild failed. Waiting on a change to fix the error...`))
|
|
||||||
if (argv.verbose) {
|
|
||||||
console.log(chalk.red(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
release()
|
release()
|
||||||
clientRefresh()
|
|
||||||
toRebuild.clear()
|
|
||||||
toRemove.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (argv: Argv, mut: Mutex, clientRefresh: () => void) => {
|
export default async (argv: Argv, mut: Mutex, clientRefresh: () => void) => {
|
||||||
|
@ -38,9 +38,14 @@ export type Analytics =
|
|||||||
provider: "cabin"
|
provider: "cabin"
|
||||||
host?: string
|
host?: string
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
provider: "clarity"
|
||||||
|
projectId?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface GlobalConfiguration {
|
export interface GlobalConfiguration {
|
||||||
pageTitle: string
|
pageTitle: string
|
||||||
|
pageTitleSuffix?: string
|
||||||
/** Whether to enable single-page-app style rendering. this prevents flashes of unstyled content and improves smoothness of Quartz */
|
/** Whether to enable single-page-app style rendering. this prevents flashes of unstyled content and improves smoothness of Quartz */
|
||||||
enableSPA: boolean
|
enableSPA: boolean
|
||||||
/** Whether to display Wikipedia-style popovers when hovering over links */
|
/** Whether to display Wikipedia-style popovers when hovering over links */
|
||||||
@ -59,7 +64,7 @@ export interface GlobalConfiguration {
|
|||||||
/**
|
/**
|
||||||
* Allow to translate the date in the language of your choice.
|
* Allow to translate the date in the language of your choice.
|
||||||
* Also used for UI translation (default: en-US)
|
* Also used for UI translation (default: en-US)
|
||||||
* Need to be formated following BCP 47: https://en.wikipedia.org/wiki/IETF_language_tag
|
* Need to be formatted following BCP 47: https://en.wikipedia.org/wiki/IETF_language_tag
|
||||||
* The first part is the language (en) and the second part is the script/region (US)
|
* The first part is the language (en) and the second part is the script/region (US)
|
||||||
* Language Codes: https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
* Language Codes: https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
||||||
* Region Codes: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
* Region Codes: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||||
|
@ -71,10 +71,10 @@ export const BuildArgv = {
|
|||||||
default: false,
|
default: false,
|
||||||
describe: "run a local server to live-preview your Quartz",
|
describe: "run a local server to live-preview your Quartz",
|
||||||
},
|
},
|
||||||
fastRebuild: {
|
watch: {
|
||||||
boolean: true,
|
boolean: true,
|
||||||
default: false,
|
default: false,
|
||||||
describe: "[experimental] rebuild only the changed files",
|
describe: "watch for changes and rebuild automatically",
|
||||||
},
|
},
|
||||||
baseDir: {
|
baseDir: {
|
||||||
string: true,
|
string: true,
|
||||||
|
@ -15,6 +15,7 @@ import { WebSocketServer } from "ws"
|
|||||||
import { randomUUID } from "crypto"
|
import { randomUUID } from "crypto"
|
||||||
import { Mutex } from "async-mutex"
|
import { Mutex } from "async-mutex"
|
||||||
import { CreateArgv } from "./args.js"
|
import { CreateArgv } from "./args.js"
|
||||||
|
import { globby } from "globby"
|
||||||
import {
|
import {
|
||||||
exitIfCancel,
|
exitIfCancel,
|
||||||
escapePath,
|
escapePath,
|
||||||
@ -32,6 +33,15 @@ import {
|
|||||||
cwd,
|
cwd,
|
||||||
} from "./constants.js"
|
} from "./constants.js"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve content directory path
|
||||||
|
* @param contentPath path to resolve
|
||||||
|
*/
|
||||||
|
function resolveContentPath(contentPath) {
|
||||||
|
if (path.isAbsolute(contentPath)) return path.relative(cwd, contentPath)
|
||||||
|
return path.join(cwd, contentPath)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles `npx quartz create`
|
* Handles `npx quartz create`
|
||||||
* @param {*} argv arguments for `create`
|
* @param {*} argv arguments for `create`
|
||||||
@ -39,12 +49,12 @@ import {
|
|||||||
export async function handleCreate(argv) {
|
export async function handleCreate(argv) {
|
||||||
console.log()
|
console.log()
|
||||||
intro(chalk.bgGreen.black(` Quartz v${version} `))
|
intro(chalk.bgGreen.black(` Quartz v${version} `))
|
||||||
const contentFolder = path.join(cwd, argv.directory)
|
const contentFolder = resolveContentPath(argv.directory)
|
||||||
let setupStrategy = argv.strategy?.toLowerCase()
|
let setupStrategy = argv.strategy?.toLowerCase()
|
||||||
let linkResolutionStrategy = argv.links?.toLowerCase()
|
let linkResolutionStrategy = argv.links?.toLowerCase()
|
||||||
const sourceDirectory = argv.source
|
const sourceDirectory = argv.source
|
||||||
|
|
||||||
// If all cmd arguments were provided, check if theyre valid
|
// If all cmd arguments were provided, check if they're valid
|
||||||
if (setupStrategy && linkResolutionStrategy) {
|
if (setupStrategy && linkResolutionStrategy) {
|
||||||
// If setup isn't, "new", source argument is required
|
// If setup isn't, "new", source argument is required
|
||||||
if (setupStrategy !== "new") {
|
if (setupStrategy !== "new") {
|
||||||
@ -215,6 +225,10 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
|
|||||||
* @param {*} argv arguments for `build`
|
* @param {*} argv arguments for `build`
|
||||||
*/
|
*/
|
||||||
export async function handleBuild(argv) {
|
export async function handleBuild(argv) {
|
||||||
|
if (argv.serve) {
|
||||||
|
argv.watch = true
|
||||||
|
}
|
||||||
|
|
||||||
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
|
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
|
||||||
const ctx = await esbuild.context({
|
const ctx = await esbuild.context({
|
||||||
entryPoints: [fp],
|
entryPoints: [fp],
|
||||||
@ -236,6 +250,11 @@ export async function handleBuild(argv) {
|
|||||||
type: "css-text",
|
type: "css-text",
|
||||||
cssImports: true,
|
cssImports: true,
|
||||||
}),
|
}),
|
||||||
|
sassPlugin({
|
||||||
|
filter: /\.inline\.scss$/,
|
||||||
|
type: "css",
|
||||||
|
cssImports: true,
|
||||||
|
}),
|
||||||
{
|
{
|
||||||
name: "inline-script-loader",
|
name: "inline-script-loader",
|
||||||
setup(build) {
|
setup(build) {
|
||||||
@ -285,8 +304,8 @@ export async function handleBuild(argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cleanupBuild) {
|
if (cleanupBuild) {
|
||||||
await cleanupBuild()
|
|
||||||
console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
|
console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
|
||||||
|
await cleanupBuild()
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await ctx.rebuild().catch((err) => {
|
const result = await ctx.rebuild().catch((err) => {
|
||||||
@ -316,9 +335,10 @@ export async function handleBuild(argv) {
|
|||||||
clientRefresh()
|
clientRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let clientRefresh = () => {}
|
||||||
if (argv.serve) {
|
if (argv.serve) {
|
||||||
const connections = []
|
const connections = []
|
||||||
const clientRefresh = () => connections.forEach((conn) => conn.send("rebuild"))
|
clientRefresh = () => connections.forEach((conn) => conn.send("rebuild"))
|
||||||
|
|
||||||
if (argv.baseDir !== "" && !argv.baseDir.startsWith("/")) {
|
if (argv.baseDir !== "" && !argv.baseDir.startsWith("/")) {
|
||||||
argv.baseDir = "/" + argv.baseDir
|
argv.baseDir = "/" + argv.baseDir
|
||||||
@ -350,6 +370,15 @@ export async function handleBuild(argv) {
|
|||||||
source: "**/*.*",
|
source: "**/*.*",
|
||||||
headers: [{ key: "Content-Disposition", value: "inline" }],
|
headers: [{ key: "Content-Disposition", value: "inline" }],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
source: "**/*.webp",
|
||||||
|
headers: [{ key: "Content-Type", value: "image/webp" }],
|
||||||
|
},
|
||||||
|
// fixes bug where avif images are displayed as text instead of images (future proof)
|
||||||
|
{
|
||||||
|
source: "**/*.avif",
|
||||||
|
headers: [{ key: "Content-Type", value: "image/avif" }],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
const status = res.statusCode
|
const status = res.statusCode
|
||||||
@ -409,6 +438,7 @@ export async function handleBuild(argv) {
|
|||||||
|
|
||||||
return serve()
|
return serve()
|
||||||
})
|
})
|
||||||
|
|
||||||
server.listen(argv.port)
|
server.listen(argv.port)
|
||||||
const wss = new WebSocketServer({ port: argv.wsPort })
|
const wss = new WebSocketServer({ port: argv.wsPort })
|
||||||
wss.on("connection", (ws) => connections.push(ws))
|
wss.on("connection", (ws) => connections.push(ws))
|
||||||
@ -417,18 +447,28 @@ export async function handleBuild(argv) {
|
|||||||
`Started a Quartz server listening at http://localhost:${argv.port}${argv.baseDir}`,
|
`Started a Quartz server listening at http://localhost:${argv.port}${argv.baseDir}`,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
console.log("hint: exit with ctrl+c")
|
|
||||||
chokidar
|
|
||||||
.watch(["**/*.ts", "**/*.tsx", "**/*.scss", "package.json"], {
|
|
||||||
ignoreInitial: true,
|
|
||||||
})
|
|
||||||
.on("all", async () => {
|
|
||||||
build(clientRefresh)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
await build(() => {})
|
await build(clientRefresh)
|
||||||
ctx.dispose()
|
ctx.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argv.watch) {
|
||||||
|
const paths = await globby([
|
||||||
|
"**/*.ts",
|
||||||
|
"quartz/cli/*.js",
|
||||||
|
"quartz/static/**/*",
|
||||||
|
"**/*.tsx",
|
||||||
|
"**/*.scss",
|
||||||
|
"package.json",
|
||||||
|
])
|
||||||
|
chokidar
|
||||||
|
.watch(paths, { ignoreInitial: true })
|
||||||
|
.on("add", () => build(clientRefresh))
|
||||||
|
.on("change", () => build(clientRefresh))
|
||||||
|
.on("unlink", () => build(clientRefresh))
|
||||||
|
|
||||||
|
console.log(chalk.grey("hint: exit with ctrl+c"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -436,7 +476,7 @@ export async function handleBuild(argv) {
|
|||||||
* @param {*} argv arguments for `update`
|
* @param {*} argv arguments for `update`
|
||||||
*/
|
*/
|
||||||
export async function handleUpdate(argv) {
|
export async function handleUpdate(argv) {
|
||||||
const contentFolder = path.join(cwd, argv.directory)
|
const contentFolder = resolveContentPath(argv.directory)
|
||||||
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
|
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
|
||||||
console.log("Backing up your content")
|
console.log("Backing up your content")
|
||||||
execSync(
|
execSync(
|
||||||
@ -457,7 +497,25 @@ export async function handleUpdate(argv) {
|
|||||||
|
|
||||||
await popContentFolder(contentFolder)
|
await popContentFolder(contentFolder)
|
||||||
console.log("Ensuring dependencies are up to date")
|
console.log("Ensuring dependencies are up to date")
|
||||||
const res = spawnSync("npm", ["i"], { stdio: "inherit" })
|
|
||||||
|
/*
|
||||||
|
On Windows, if the command `npm` is really `npm.cmd', this call fails
|
||||||
|
as it will be unable to find `npm`. This is often the case on systems
|
||||||
|
where `npm` is installed via a package manager.
|
||||||
|
|
||||||
|
This means `npx quartz update` will not actually update dependencies
|
||||||
|
on Windows, without a manual `npm i` from the caller.
|
||||||
|
|
||||||
|
However, by spawning a shell, we are able to call `npm.cmd`.
|
||||||
|
See: https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows
|
||||||
|
*/
|
||||||
|
|
||||||
|
const opts = { stdio: "inherit" }
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
opts.shell = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = spawnSync("npm", ["i"], opts)
|
||||||
if (res.status === 0) {
|
if (res.status === 0) {
|
||||||
console.log(chalk.green("Done!"))
|
console.log(chalk.green("Done!"))
|
||||||
} else {
|
} else {
|
||||||
@ -470,7 +528,7 @@ export async function handleUpdate(argv) {
|
|||||||
* @param {*} argv arguments for `restore`
|
* @param {*} argv arguments for `restore`
|
||||||
*/
|
*/
|
||||||
export async function handleRestore(argv) {
|
export async function handleRestore(argv) {
|
||||||
const contentFolder = path.join(cwd, argv.directory)
|
const contentFolder = resolveContentPath(argv.directory)
|
||||||
await popContentFolder(contentFolder)
|
await popContentFolder(contentFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,7 +537,7 @@ export async function handleRestore(argv) {
|
|||||||
* @param {*} argv arguments for `sync`
|
* @param {*} argv arguments for `sync`
|
||||||
*/
|
*/
|
||||||
export async function handleSync(argv) {
|
export async function handleSync(argv) {
|
||||||
const contentFolder = path.join(cwd, argv.directory)
|
const contentFolder = resolveContentPath(argv.directory)
|
||||||
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
|
console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
|
||||||
console.log("Backing up your content")
|
console.log("Backing up your content")
|
||||||
|
|
||||||
@ -531,7 +589,8 @@ export async function handleSync(argv) {
|
|||||||
await popContentFolder(contentFolder)
|
await popContentFolder(contentFolder)
|
||||||
if (argv.push) {
|
if (argv.push) {
|
||||||
console.log("Pushing your changes")
|
console.log("Pushing your changes")
|
||||||
const res = spawnSync("git", ["push", "-uf", ORIGIN_NAME, QUARTZ_SOURCE_BRANCH], {
|
const currentBranch = execSync("git rev-parse --abbrev-ref HEAD").toString().trim()
|
||||||
|
const res = spawnSync("git", ["push", "-uf", ORIGIN_NAME, currentBranch], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
})
|
})
|
||||||
if (res.status !== 0) {
|
if (res.status !== 0) {
|
||||||
|
@ -3,34 +3,53 @@ import style from "./styles/backlinks.scss"
|
|||||||
import { resolveRelative, simplifySlug } from "../util/path"
|
import { resolveRelative, simplifySlug } from "../util/path"
|
||||||
import { i18n } from "../i18n"
|
import { i18n } from "../i18n"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
|
import OverflowListFactory from "./OverflowList"
|
||||||
|
|
||||||
const Backlinks: QuartzComponent = ({
|
interface BacklinksOptions {
|
||||||
fileData,
|
hideWhenEmpty: boolean
|
||||||
allFiles,
|
|
||||||
displayClass,
|
|
||||||
cfg,
|
|
||||||
}: QuartzComponentProps) => {
|
|
||||||
const slug = simplifySlug(fileData.slug!)
|
|
||||||
const backlinkFiles = allFiles.filter((file) => file.links?.includes(slug))
|
|
||||||
return (
|
|
||||||
<div class={classNames(displayClass, "backlinks")}>
|
|
||||||
<h3>{i18n(cfg.locale).components.backlinks.title}</h3>
|
|
||||||
<ul class="overflow">
|
|
||||||
{backlinkFiles.length > 0 ? (
|
|
||||||
backlinkFiles.map((f) => (
|
|
||||||
<li>
|
|
||||||
<a href={resolveRelative(fileData.slug!, f.slug!)} class="internal">
|
|
||||||
{f.frontmatter?.title}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<li>{i18n(cfg.locale).components.backlinks.noBacklinksFound}</li>
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Backlinks.css = style
|
const defaultOptions: BacklinksOptions = {
|
||||||
export default (() => Backlinks) satisfies QuartzComponentConstructor
|
hideWhenEmpty: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ((opts?: Partial<BacklinksOptions>) => {
|
||||||
|
const options: BacklinksOptions = { ...defaultOptions, ...opts }
|
||||||
|
const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory()
|
||||||
|
|
||||||
|
const Backlinks: QuartzComponent = ({
|
||||||
|
fileData,
|
||||||
|
allFiles,
|
||||||
|
displayClass,
|
||||||
|
cfg,
|
||||||
|
}: QuartzComponentProps) => {
|
||||||
|
const slug = simplifySlug(fileData.slug!)
|
||||||
|
const backlinkFiles = allFiles.filter((file) => file.links?.includes(slug))
|
||||||
|
if (options.hideWhenEmpty && backlinkFiles.length == 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div class={classNames(displayClass, "backlinks")}>
|
||||||
|
<h3>{i18n(cfg.locale).components.backlinks.title}</h3>
|
||||||
|
<OverflowList>
|
||||||
|
{backlinkFiles.length > 0 ? (
|
||||||
|
backlinkFiles.map((f) => (
|
||||||
|
<li>
|
||||||
|
<a href={resolveRelative(fileData.slug!, f.slug!)} class="internal">
|
||||||
|
{f.frontmatter?.title}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<li>{i18n(cfg.locale).components.backlinks.noBacklinksFound}</li>
|
||||||
|
)}
|
||||||
|
</OverflowList>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Backlinks.css = style
|
||||||
|
Backlinks.afterDOMLoaded = overflowListAfterDOMLoaded
|
||||||
|
|
||||||
|
return Backlinks
|
||||||
|
}) satisfies QuartzComponentConstructor
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import breadcrumbsStyle from "./styles/breadcrumbs.scss"
|
import breadcrumbsStyle from "./styles/breadcrumbs.scss"
|
||||||
import { FullSlug, SimpleSlug, joinSegments, resolveRelative } from "../util/path"
|
import { FullSlug, SimpleSlug, resolveRelative, simplifySlug } from "../util/path"
|
||||||
import { QuartzPluginData } from "../plugins/vfile"
|
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
|
import { trieFromAllFiles } from "../util/ctx"
|
||||||
|
|
||||||
type CrumbData = {
|
type CrumbData = {
|
||||||
displayName: string
|
displayName: string
|
||||||
@ -22,10 +22,6 @@ interface BreadcrumbOptions {
|
|||||||
* Whether to look up frontmatter title for folders (could cause performance problems with big vaults)
|
* Whether to look up frontmatter title for folders (could cause performance problems with big vaults)
|
||||||
*/
|
*/
|
||||||
resolveFrontmatterTitle: boolean
|
resolveFrontmatterTitle: boolean
|
||||||
/**
|
|
||||||
* Whether to display breadcrumbs on root `index.md`
|
|
||||||
*/
|
|
||||||
hideOnRoot: boolean
|
|
||||||
/**
|
/**
|
||||||
* Whether to display the current page in the breadcrumbs.
|
* Whether to display the current page in the breadcrumbs.
|
||||||
*/
|
*/
|
||||||
@ -36,7 +32,6 @@ const defaultOptions: BreadcrumbOptions = {
|
|||||||
spacerSymbol: "❯",
|
spacerSymbol: "❯",
|
||||||
rootName: "Home",
|
rootName: "Home",
|
||||||
resolveFrontmatterTitle: true,
|
resolveFrontmatterTitle: true,
|
||||||
hideOnRoot: true,
|
|
||||||
showCurrentPage: true,
|
showCurrentPage: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,78 +43,37 @@ function formatCrumb(displayName: string, baseSlug: FullSlug, currentSlug: Simpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default ((opts?: Partial<BreadcrumbOptions>) => {
|
export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||||
// Merge options with defaults
|
|
||||||
const options: BreadcrumbOptions = { ...defaultOptions, ...opts }
|
const options: BreadcrumbOptions = { ...defaultOptions, ...opts }
|
||||||
|
|
||||||
// computed index of folder name to its associated file data
|
|
||||||
let folderIndex: Map<string, QuartzPluginData> | undefined
|
|
||||||
|
|
||||||
const Breadcrumbs: QuartzComponent = ({
|
const Breadcrumbs: QuartzComponent = ({
|
||||||
fileData,
|
fileData,
|
||||||
allFiles,
|
allFiles,
|
||||||
displayClass,
|
displayClass,
|
||||||
|
ctx,
|
||||||
}: QuartzComponentProps) => {
|
}: QuartzComponentProps) => {
|
||||||
// Hide crumbs on root if enabled
|
const trie = (ctx.trie ??= trieFromAllFiles(allFiles))
|
||||||
if (options.hideOnRoot && fileData.slug === "index") {
|
const slugParts = fileData.slug!.split("/")
|
||||||
return <></>
|
const pathNodes = trie.ancestryChain(slugParts)
|
||||||
|
|
||||||
|
if (!pathNodes) {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format entry for root element
|
const crumbs: CrumbData[] = pathNodes.map((node, idx) => {
|
||||||
const firstEntry = formatCrumb(options.rootName, fileData.slug!, "/" as SimpleSlug)
|
const crumb = formatCrumb(node.displayName, fileData.slug!, simplifySlug(node.slug))
|
||||||
const crumbs: CrumbData[] = [firstEntry]
|
if (idx === 0) {
|
||||||
|
crumb.displayName = options.rootName
|
||||||
if (!folderIndex && options.resolveFrontmatterTitle) {
|
|
||||||
folderIndex = new Map()
|
|
||||||
// construct the index for the first time
|
|
||||||
for (const file of allFiles) {
|
|
||||||
const folderParts = file.slug?.split("/")
|
|
||||||
if (folderParts?.at(-1) === "index") {
|
|
||||||
folderIndex.set(folderParts.slice(0, -1).join("/"), file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split slug into hierarchy/parts
|
|
||||||
const slugParts = fileData.slug?.split("/")
|
|
||||||
if (slugParts) {
|
|
||||||
// is tag breadcrumb?
|
|
||||||
const isTagPath = slugParts[0] === "tags"
|
|
||||||
|
|
||||||
// full path until current part
|
|
||||||
let currentPath = ""
|
|
||||||
|
|
||||||
for (let i = 0; i < slugParts.length - 1; i++) {
|
|
||||||
let curPathSegment = slugParts[i]
|
|
||||||
|
|
||||||
// Try to resolve frontmatter folder title
|
|
||||||
const currentFile = folderIndex?.get(slugParts.slice(0, i + 1).join("/"))
|
|
||||||
if (currentFile) {
|
|
||||||
const title = currentFile.frontmatter!.title
|
|
||||||
if (title !== "index") {
|
|
||||||
curPathSegment = title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add current slug to full path
|
|
||||||
currentPath = joinSegments(currentPath, slugParts[i])
|
|
||||||
const includeTrailingSlash = !isTagPath || i < 1
|
|
||||||
|
|
||||||
// Format and add current crumb
|
|
||||||
const crumb = formatCrumb(
|
|
||||||
curPathSegment,
|
|
||||||
fileData.slug!,
|
|
||||||
(currentPath + (includeTrailingSlash ? "/" : "")) as SimpleSlug,
|
|
||||||
)
|
|
||||||
crumbs.push(crumb)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add current file to crumb (can directly use frontmatter title)
|
// For last node (current page), set empty path
|
||||||
if (options.showCurrentPage && slugParts.at(-1) !== "index") {
|
if (idx === pathNodes.length - 1) {
|
||||||
crumbs.push({
|
crumb.path = ""
|
||||||
displayName: fileData.frontmatter!.title,
|
|
||||||
path: "",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return crumb
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!options.showCurrentPage) {
|
||||||
|
crumbs.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -10,6 +10,9 @@ type Options = {
|
|||||||
repoId: string
|
repoId: string
|
||||||
category: string
|
category: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
themeUrl?: string
|
||||||
|
lightTheme?: string
|
||||||
|
darkTheme?: string
|
||||||
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
||||||
strict?: boolean
|
strict?: boolean
|
||||||
reactionsEnabled?: boolean
|
reactionsEnabled?: boolean
|
||||||
@ -22,7 +25,15 @@ function boolToStringBool(b: boolean): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default ((opts: Options) => {
|
export default ((opts: Options) => {
|
||||||
const Comments: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {
|
||||||
|
// check if comments should be displayed according to frontmatter
|
||||||
|
const disableComment: boolean =
|
||||||
|
typeof fileData.frontmatter?.comments !== "undefined" &&
|
||||||
|
(!fileData.frontmatter?.comments || fileData.frontmatter?.comments === "false")
|
||||||
|
if (disableComment) {
|
||||||
|
return <></>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={classNames(displayClass, "giscus")}
|
class={classNames(displayClass, "giscus")}
|
||||||
@ -34,6 +45,11 @@ export default ((opts: Options) => {
|
|||||||
data-strict={boolToStringBool(opts.options.strict ?? true)}
|
data-strict={boolToStringBool(opts.options.strict ?? true)}
|
||||||
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
|
data-reactions-enabled={boolToStringBool(opts.options.reactionsEnabled ?? true)}
|
||||||
data-input-position={opts.options.inputPosition ?? "bottom"}
|
data-input-position={opts.options.inputPosition ?? "bottom"}
|
||||||
|
data-light-theme={opts.options.lightTheme ?? "light"}
|
||||||
|
data-dark-theme={opts.options.darkTheme ?? "dark"}
|
||||||
|
data-theme-url={
|
||||||
|
opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`
|
||||||
|
}
|
||||||
></div>
|
></div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
22
quartz/components/ConditionalRender.tsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
|
|
||||||
|
type ConditionalRenderConfig = {
|
||||||
|
component: QuartzComponent
|
||||||
|
condition: (props: QuartzComponentProps) => boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ((config: ConditionalRenderConfig) => {
|
||||||
|
const ConditionalRender: QuartzComponent = (props: QuartzComponentProps) => {
|
||||||
|
if (config.condition(props)) {
|
||||||
|
return <config.component {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
ConditionalRender.afterDOMLoaded = config.component.afterDOMLoaded
|
||||||
|
ConditionalRender.beforeDOMLoaded = config.component.beforeDOMLoaded
|
||||||
|
ConditionalRender.css = config.component.css
|
||||||
|
|
||||||
|
return ConditionalRender
|
||||||
|
}) satisfies QuartzComponentConstructor<ConditionalRenderConfig>
|
@ -1,4 +1,4 @@
|
|||||||
import { formatDate, getDate } from "./Date"
|
import { Date, getDate } from "./Date"
|
||||||
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import readingTime from "reading-time"
|
import readingTime from "reading-time"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
@ -30,7 +30,7 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
|
|||||||
const segments: (string | JSX.Element)[] = []
|
const segments: (string | JSX.Element)[] = []
|
||||||
|
|
||||||
if (fileData.dates) {
|
if (fileData.dates) {
|
||||||
segments.push(formatDate(getDate(cfg, fileData)!, cfg.locale))
|
segments.push(<Date date={getDate(cfg, fileData)!} locale={cfg.locale} />)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display reading time if enabled
|
// Display reading time if enabled
|
||||||
@ -39,14 +39,12 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
|
|||||||
const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({
|
const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({
|
||||||
minutes: Math.ceil(minutes),
|
minutes: Math.ceil(minutes),
|
||||||
})
|
})
|
||||||
segments.push(displayedTime)
|
segments.push(<span>{displayedTime}</span>)
|
||||||
}
|
}
|
||||||
|
|
||||||
const segmentsElements = segments.map((segment) => <span>{segment}</span>)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<p show-comma={options.showComma} class={classNames(displayClass, "content-meta")}>
|
<p show-comma={options.showComma} class={classNames(displayClass, "content-meta")}>
|
||||||
{segmentsElements}
|
{segments}
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
// @ts-ignore: this is safe, we don't want to actually make darkmode.inline.ts a module as
|
// @ts-ignore
|
||||||
// modules are automatically deferred and we don't want that to happen for critical beforeDOMLoads
|
|
||||||
// see: https://v8.dev/features/modules#defer
|
|
||||||
import darkmodeScript from "./scripts/darkmode.inline"
|
import darkmodeScript from "./scripts/darkmode.inline"
|
||||||
import styles from "./styles/darkmode.scss"
|
import styles from "./styles/darkmode.scss"
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
@ -9,12 +7,12 @@ import { classNames } from "../util/lang"
|
|||||||
|
|
||||||
const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||||
return (
|
return (
|
||||||
<button class={classNames(displayClass, "darkmode")} id="darkmode">
|
<button class={classNames(displayClass, "darkmode")}>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlnsXlink="http://www.w3.org/1999/xlink"
|
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="dayIcon"
|
class="dayIcon"
|
||||||
x="0px"
|
x="0px"
|
||||||
y="0px"
|
y="0px"
|
||||||
viewBox="0 0 35 35"
|
viewBox="0 0 35 35"
|
||||||
@ -29,7 +27,7 @@ const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps)
|
|||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlnsXlink="http://www.w3.org/1999/xlink"
|
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="nightIcon"
|
class="nightIcon"
|
||||||
x="0px"
|
x="0px"
|
||||||
y="0px"
|
y="0px"
|
||||||
viewBox="0 0 100 100"
|
viewBox="0 0 100 100"
|
||||||
|
@ -27,5 +27,5 @@ export function formatDate(d: Date, locale: ValidLocale = "en-US"): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Date({ date, locale }: Props) {
|
export function Date({ date, locale }: Props) {
|
||||||
return <>{formatDate(date, locale)}</>
|
return <time datetime={date.toISOString()}>{formatDate(date, locale)}</time>
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
|
|
||||||
export default ((component?: QuartzComponent) => {
|
export default ((component: QuartzComponent) => {
|
||||||
if (component) {
|
const Component = component
|
||||||
const Component = component
|
const DesktopOnly: QuartzComponent = (props: QuartzComponentProps) => {
|
||||||
const DesktopOnly: QuartzComponent = (props: QuartzComponentProps) => {
|
return <Component displayClass="desktop-only" {...props} />
|
||||||
return <Component displayClass="desktop-only" {...props} />
|
|
||||||
}
|
|
||||||
|
|
||||||
DesktopOnly.displayName = component.displayName
|
|
||||||
DesktopOnly.afterDOMLoaded = component?.afterDOMLoaded
|
|
||||||
DesktopOnly.beforeDOMLoaded = component?.beforeDOMLoaded
|
|
||||||
DesktopOnly.css = component?.css
|
|
||||||
return DesktopOnly
|
|
||||||
} else {
|
|
||||||
return () => <></>
|
|
||||||
}
|
}
|
||||||
}) satisfies QuartzComponentConstructor
|
|
||||||
|
DesktopOnly.displayName = component.displayName
|
||||||
|
DesktopOnly.afterDOMLoaded = component?.afterDOMLoaded
|
||||||
|
DesktopOnly.beforeDOMLoaded = component?.beforeDOMLoaded
|
||||||
|
DesktopOnly.css = component?.css
|
||||||
|
return DesktopOnly
|
||||||
|
}) satisfies QuartzComponentConstructor<QuartzComponent>
|
||||||
|
@ -1,24 +1,37 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import explorerStyle from "./styles/explorer.scss"
|
import style from "./styles/explorer.scss"
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import script from "./scripts/explorer.inline"
|
import script from "./scripts/explorer.inline"
|
||||||
import { ExplorerNode, FileNode, Options } from "./ExplorerNode"
|
|
||||||
import { QuartzPluginData } from "../plugins/vfile"
|
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
import { i18n } from "../i18n"
|
import { i18n } from "../i18n"
|
||||||
|
import { FileTrieNode } from "../util/fileTrie"
|
||||||
|
import OverflowListFactory from "./OverflowList"
|
||||||
|
import { concatenateResources } from "../util/resources"
|
||||||
|
|
||||||
// Options interface defined in `ExplorerNode` to avoid circular dependency
|
type OrderEntries = "sort" | "filter" | "map"
|
||||||
const defaultOptions = {
|
|
||||||
folderClickBehavior: "collapse",
|
export interface Options {
|
||||||
|
title?: string
|
||||||
|
folderDefaultState: "collapsed" | "open"
|
||||||
|
folderClickBehavior: "collapse" | "link"
|
||||||
|
useSavedState: boolean
|
||||||
|
sortFn: (a: FileTrieNode, b: FileTrieNode) => number
|
||||||
|
filterFn: (node: FileTrieNode) => boolean
|
||||||
|
mapFn: (node: FileTrieNode) => void
|
||||||
|
order: OrderEntries[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultOptions: Options = {
|
||||||
folderDefaultState: "collapsed",
|
folderDefaultState: "collapsed",
|
||||||
|
folderClickBehavior: "link",
|
||||||
useSavedState: true,
|
useSavedState: true,
|
||||||
mapFn: (node) => {
|
mapFn: (node) => {
|
||||||
return node
|
return node
|
||||||
},
|
},
|
||||||
sortFn: (a, b) => {
|
sortFn: (a, b) => {
|
||||||
// Sort order: folders first, then files. Sort folders and files alphabetically
|
// Sort order: folders first, then files. Sort folders and files alphabeticall
|
||||||
if ((!a.file && !b.file) || (a.file && b.file)) {
|
if ((!a.isFolder && !b.isFolder) || (a.isFolder && b.isFolder)) {
|
||||||
// numeric: true: Whether numeric collation should be used, such that "1" < "2" < "10"
|
// numeric: true: Whether numeric collation should be used, such that "1" < "2" < "10"
|
||||||
// sensitivity: "base": Only strings that differ in base letters compare as unequal. Examples: a ≠ b, a = á, a = A
|
// sensitivity: "base": Only strings that differ in base letters compare as unequal. Examples: a ≠ b, a = á, a = A
|
||||||
return a.displayName.localeCompare(b.displayName, undefined, {
|
return a.displayName.localeCompare(b.displayName, undefined, {
|
||||||
@ -27,74 +40,65 @@ const defaultOptions = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.file && !b.file) {
|
if (!a.isFolder && b.isFolder) {
|
||||||
return 1
|
return 1
|
||||||
} else {
|
} else {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filterFn: (node) => node.name !== "tags",
|
filterFn: (node) => node.slugSegment !== "tags",
|
||||||
order: ["filter", "map", "sort"],
|
order: ["filter", "map", "sort"],
|
||||||
} satisfies Options
|
}
|
||||||
|
|
||||||
|
export type FolderState = {
|
||||||
|
path: string
|
||||||
|
collapsed: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export default ((userOpts?: Partial<Options>) => {
|
export default ((userOpts?: Partial<Options>) => {
|
||||||
// Parse config
|
|
||||||
const opts: Options = { ...defaultOptions, ...userOpts }
|
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||||
|
const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory()
|
||||||
|
|
||||||
// memoized
|
const Explorer: QuartzComponent = ({ cfg, displayClass }: QuartzComponentProps) => {
|
||||||
let fileTree: FileNode
|
|
||||||
let jsonTree: string
|
|
||||||
let lastBuildId: string = ""
|
|
||||||
|
|
||||||
function constructFileTree(allFiles: QuartzPluginData[]) {
|
|
||||||
// Construct tree from allFiles
|
|
||||||
fileTree = new FileNode("")
|
|
||||||
allFiles.forEach((file) => fileTree.add(file))
|
|
||||||
|
|
||||||
// Execute all functions (sort, filter, map) that were provided (if none were provided, only default "sort" is applied)
|
|
||||||
if (opts.order) {
|
|
||||||
// Order is important, use loop with index instead of order.map()
|
|
||||||
for (let i = 0; i < opts.order.length; i++) {
|
|
||||||
const functionName = opts.order[i]
|
|
||||||
if (functionName === "map") {
|
|
||||||
fileTree.map(opts.mapFn)
|
|
||||||
} else if (functionName === "sort") {
|
|
||||||
fileTree.sort(opts.sortFn)
|
|
||||||
} else if (functionName === "filter") {
|
|
||||||
fileTree.filter(opts.filterFn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all folders of tree. Initialize with collapsed state
|
|
||||||
// Stringify to pass json tree as data attribute ([data-tree])
|
|
||||||
const folders = fileTree.getFolderPaths(opts.folderDefaultState === "collapsed")
|
|
||||||
jsonTree = JSON.stringify(folders)
|
|
||||||
}
|
|
||||||
|
|
||||||
const Explorer: QuartzComponent = ({
|
|
||||||
ctx,
|
|
||||||
cfg,
|
|
||||||
allFiles,
|
|
||||||
displayClass,
|
|
||||||
fileData,
|
|
||||||
}: QuartzComponentProps) => {
|
|
||||||
if (ctx.buildId !== lastBuildId) {
|
|
||||||
lastBuildId = ctx.buildId
|
|
||||||
constructFileTree(allFiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={classNames(displayClass, "explorer")}>
|
<div
|
||||||
|
class={classNames(displayClass, "explorer")}
|
||||||
|
data-behavior={opts.folderClickBehavior}
|
||||||
|
data-collapsed={opts.folderDefaultState}
|
||||||
|
data-savestate={opts.useSavedState}
|
||||||
|
data-data-fns={JSON.stringify({
|
||||||
|
order: opts.order,
|
||||||
|
sortFn: opts.sortFn.toString(),
|
||||||
|
filterFn: opts.filterFn.toString(),
|
||||||
|
mapFn: opts.mapFn.toString(),
|
||||||
|
})}
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
id="explorer"
|
class="explorer-toggle mobile-explorer hide-until-loaded"
|
||||||
data-behavior={opts.folderClickBehavior}
|
data-mobile={true}
|
||||||
data-collapsed={opts.folderDefaultState}
|
|
||||||
data-savestate={opts.useSavedState}
|
|
||||||
data-tree={jsonTree}
|
|
||||||
aria-controls="explorer-content"
|
aria-controls="explorer-content"
|
||||||
aria-expanded={opts.folderDefaultState === "open"}
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="lucide-menu"
|
||||||
|
>
|
||||||
|
<line x1="4" x2="20" y1="12" y2="12" />
|
||||||
|
<line x1="4" x2="20" y1="6" y2="6" />
|
||||||
|
<line x1="4" x2="20" y1="18" y2="18" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="title-button explorer-toggle desktop-explorer"
|
||||||
|
data-mobile={false}
|
||||||
|
aria-expanded={true}
|
||||||
>
|
>
|
||||||
<h2>{opts.title ?? i18n(cfg.locale).components.explorer.title}</h2>
|
<h2>{opts.title ?? i18n(cfg.locale).components.explorer.title}</h2>
|
||||||
<svg
|
<svg
|
||||||
@ -112,17 +116,47 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
<polyline points="6 9 12 15 18 9"></polyline>
|
<polyline points="6 9 12 15 18 9"></polyline>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<div id="explorer-content">
|
<div class="explorer-content" aria-expanded={false}>
|
||||||
<ul class="overflow" id="explorer-ul">
|
<OverflowList class="explorer-ul" />
|
||||||
<ExplorerNode node={fileTree} opts={opts} fileData={fileData} />
|
|
||||||
<li id="explorer-end" />
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
|
<template id="template-file">
|
||||||
|
<li>
|
||||||
|
<a href="#"></a>
|
||||||
|
</li>
|
||||||
|
</template>
|
||||||
|
<template id="template-folder">
|
||||||
|
<li>
|
||||||
|
<div class="folder-container">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="12"
|
||||||
|
height="12"
|
||||||
|
viewBox="5 8 14 8"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="folder-icon"
|
||||||
|
>
|
||||||
|
<polyline points="6 9 12 15 18 9"></polyline>
|
||||||
|
</svg>
|
||||||
|
<div>
|
||||||
|
<button class="folder-button">
|
||||||
|
<span class="folder-title"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="folder-outer">
|
||||||
|
<ul class="content"></ul>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Explorer.css = explorerStyle
|
Explorer.css = style
|
||||||
Explorer.afterDOMLoaded = script
|
Explorer.afterDOMLoaded = concatenateResources(script, overflowListAfterDOMLoaded)
|
||||||
return Explorer
|
return Explorer
|
||||||
}) satisfies QuartzComponentConstructor
|
}) satisfies QuartzComponentConstructor
|
||||||
|
@ -1,242 +0,0 @@
|
|||||||
// @ts-ignore
|
|
||||||
import { QuartzPluginData } from "../plugins/vfile"
|
|
||||||
import {
|
|
||||||
joinSegments,
|
|
||||||
resolveRelative,
|
|
||||||
clone,
|
|
||||||
simplifySlug,
|
|
||||||
SimpleSlug,
|
|
||||||
FilePath,
|
|
||||||
} from "../util/path"
|
|
||||||
|
|
||||||
type OrderEntries = "sort" | "filter" | "map"
|
|
||||||
|
|
||||||
export interface Options {
|
|
||||||
title?: string
|
|
||||||
folderDefaultState: "collapsed" | "open"
|
|
||||||
folderClickBehavior: "collapse" | "link"
|
|
||||||
useSavedState: boolean
|
|
||||||
sortFn: (a: FileNode, b: FileNode) => number
|
|
||||||
filterFn: (node: FileNode) => boolean
|
|
||||||
mapFn: (node: FileNode) => void
|
|
||||||
order: OrderEntries[]
|
|
||||||
}
|
|
||||||
|
|
||||||
type DataWrapper = {
|
|
||||||
file: QuartzPluginData
|
|
||||||
path: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FolderState = {
|
|
||||||
path: string
|
|
||||||
collapsed: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPathSegment(fp: FilePath | undefined, idx: number): string | undefined {
|
|
||||||
if (!fp) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
return fp.split("/").at(idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Structure to add all files into a tree
|
|
||||||
export class FileNode {
|
|
||||||
children: Array<FileNode>
|
|
||||||
name: string // this is the slug segment
|
|
||||||
displayName: string
|
|
||||||
file: QuartzPluginData | null
|
|
||||||
depth: number
|
|
||||||
|
|
||||||
constructor(slugSegment: string, displayName?: string, file?: QuartzPluginData, depth?: number) {
|
|
||||||
this.children = []
|
|
||||||
this.name = slugSegment
|
|
||||||
this.displayName = displayName ?? file?.frontmatter?.title ?? slugSegment
|
|
||||||
this.file = file ? clone(file) : null
|
|
||||||
this.depth = depth ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
private insert(fileData: DataWrapper) {
|
|
||||||
if (fileData.path.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextSegment = fileData.path[0]
|
|
||||||
|
|
||||||
// base case, insert here
|
|
||||||
if (fileData.path.length === 1) {
|
|
||||||
if (nextSegment === "") {
|
|
||||||
// index case (we are the root and we just found index.md), set our data appropriately
|
|
||||||
const title = fileData.file.frontmatter?.title
|
|
||||||
if (title && title !== "index") {
|
|
||||||
this.displayName = title
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// direct child
|
|
||||||
this.children.push(new FileNode(nextSegment, undefined, fileData.file, this.depth + 1))
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the right child to insert into
|
|
||||||
fileData.path = fileData.path.splice(1)
|
|
||||||
const child = this.children.find((c) => c.name === nextSegment)
|
|
||||||
if (child) {
|
|
||||||
child.insert(fileData)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const newChild = new FileNode(
|
|
||||||
nextSegment,
|
|
||||||
getPathSegment(fileData.file.relativePath, this.depth),
|
|
||||||
undefined,
|
|
||||||
this.depth + 1,
|
|
||||||
)
|
|
||||||
newChild.insert(fileData)
|
|
||||||
this.children.push(newChild)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new file to tree
|
|
||||||
add(file: QuartzPluginData) {
|
|
||||||
this.insert({ file: file, path: simplifySlug(file.slug!).split("/") })
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter FileNode tree. Behaves similar to `Array.prototype.filter()`, but modifies tree in place
|
|
||||||
* @param filterFn function to filter tree with
|
|
||||||
*/
|
|
||||||
filter(filterFn: (node: FileNode) => boolean) {
|
|
||||||
this.children = this.children.filter(filterFn)
|
|
||||||
this.children.forEach((child) => child.filter(filterFn))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter FileNode tree. Behaves similar to `Array.prototype.map()`, but modifies tree in place
|
|
||||||
* @param mapFn function to use for mapping over tree
|
|
||||||
*/
|
|
||||||
map(mapFn: (node: FileNode) => void) {
|
|
||||||
mapFn(this)
|
|
||||||
this.children.forEach((child) => child.map(mapFn))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get folder representation with state of tree.
|
|
||||||
* Intended to only be called on root node before changes to the tree are made
|
|
||||||
* @param collapsed default state of folders (collapsed by default or not)
|
|
||||||
* @returns array containing folder state for tree
|
|
||||||
*/
|
|
||||||
getFolderPaths(collapsed: boolean): FolderState[] {
|
|
||||||
const folderPaths: FolderState[] = []
|
|
||||||
|
|
||||||
const traverse = (node: FileNode, currentPath: string) => {
|
|
||||||
if (!node.file) {
|
|
||||||
const folderPath = joinSegments(currentPath, node.name)
|
|
||||||
if (folderPath !== "") {
|
|
||||||
folderPaths.push({ path: folderPath, collapsed })
|
|
||||||
}
|
|
||||||
|
|
||||||
node.children.forEach((child) => traverse(child, folderPath))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
traverse(this, "")
|
|
||||||
return folderPaths
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort order: folders first, then files. Sort folders and files alphabetically
|
|
||||||
/**
|
|
||||||
* Sorts tree according to sort/compare function
|
|
||||||
* @param sortFn compare function used for `.sort()`, also used recursively for children
|
|
||||||
*/
|
|
||||||
sort(sortFn: (a: FileNode, b: FileNode) => number) {
|
|
||||||
this.children = this.children.sort(sortFn)
|
|
||||||
this.children.forEach((e) => e.sort(sortFn))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ExplorerNodeProps = {
|
|
||||||
node: FileNode
|
|
||||||
opts: Options
|
|
||||||
fileData: QuartzPluginData
|
|
||||||
fullPath?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodeProps) {
|
|
||||||
// Get options
|
|
||||||
const folderBehavior = opts.folderClickBehavior
|
|
||||||
const isDefaultOpen = opts.folderDefaultState === "open"
|
|
||||||
|
|
||||||
// Calculate current folderPath
|
|
||||||
const folderPath = node.name !== "" ? joinSegments(fullPath ?? "", node.name) : ""
|
|
||||||
const href = resolveRelative(fileData.slug!, folderPath as SimpleSlug) + "/"
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{node.file ? (
|
|
||||||
// Single file node
|
|
||||||
<li key={node.file.slug}>
|
|
||||||
<a href={resolveRelative(fileData.slug!, node.file.slug!)} data-for={node.file.slug}>
|
|
||||||
{node.displayName}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
) : (
|
|
||||||
<li>
|
|
||||||
{node.name !== "" && (
|
|
||||||
// Node with entire folder
|
|
||||||
// Render svg button + folder name, then children
|
|
||||||
<div class="folder-container">
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="12"
|
|
||||||
height="12"
|
|
||||||
viewBox="5 8 14 8"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="2"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
class="folder-icon"
|
|
||||||
>
|
|
||||||
<polyline points="6 9 12 15 18 9"></polyline>
|
|
||||||
</svg>
|
|
||||||
{/* render <a> tag if folderBehavior is "link", otherwise render <button> with collapse click event */}
|
|
||||||
<div key={node.name} data-folderpath={folderPath}>
|
|
||||||
{folderBehavior === "link" ? (
|
|
||||||
<a href={href} data-for={node.name} class="folder-title">
|
|
||||||
{node.displayName}
|
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
<button class="folder-button">
|
|
||||||
<span class="folder-title">{node.displayName}</span>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{/* Recursively render children of folder */}
|
|
||||||
<div class={`folder-outer ${node.depth === 0 || isDefaultOpen ? "open" : ""}`}>
|
|
||||||
<ul
|
|
||||||
// Inline style for left folder paddings
|
|
||||||
style={{
|
|
||||||
paddingLeft: node.name !== "" ? "1.4rem" : "0",
|
|
||||||
}}
|
|
||||||
class="content"
|
|
||||||
data-folderul={folderPath}
|
|
||||||
>
|
|
||||||
{node.children.map((childNode, i) => (
|
|
||||||
<ExplorerNode
|
|
||||||
node={childNode}
|
|
||||||
key={i}
|
|
||||||
opts={opts}
|
|
||||||
fullPath={folderPath}
|
|
||||||
fileData={fileData}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
55
quartz/components/Flex.tsx
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import { concatenateResources } from "../util/resources"
|
||||||
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
|
|
||||||
|
type FlexConfig = {
|
||||||
|
components: {
|
||||||
|
Component: QuartzComponent
|
||||||
|
grow?: boolean
|
||||||
|
shrink?: boolean
|
||||||
|
basis?: string
|
||||||
|
order?: number
|
||||||
|
align?: "start" | "end" | "center" | "stretch"
|
||||||
|
justify?: "start" | "end" | "center" | "between" | "around"
|
||||||
|
}[]
|
||||||
|
direction?: "row" | "row-reverse" | "column" | "column-reverse"
|
||||||
|
wrap?: "nowrap" | "wrap" | "wrap-reverse"
|
||||||
|
gap?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ((config: FlexConfig) => {
|
||||||
|
const Flex: QuartzComponent = (props: QuartzComponentProps) => {
|
||||||
|
const direction = config.direction ?? "row"
|
||||||
|
const wrap = config.wrap ?? "nowrap"
|
||||||
|
const gap = config.gap ?? "1rem"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={`display: flex; flex-direction: ${direction}; flex-wrap: ${wrap}; gap: ${gap};`}>
|
||||||
|
{config.components.map((c) => {
|
||||||
|
const grow = c.grow ? 1 : 0
|
||||||
|
const shrink = (c.shrink ?? true) ? 1 : 0
|
||||||
|
const basis = c.basis ?? "auto"
|
||||||
|
const order = c.order ?? 0
|
||||||
|
const align = c.align ?? "center"
|
||||||
|
const justify = c.justify ?? "center"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={`flex-grow: ${grow}; flex-shrink: ${shrink}; flex-basis: ${basis}; order: ${order}; align-self: ${align}; justify-self: ${justify};`}
|
||||||
|
>
|
||||||
|
<c.Component {...props} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Flex.afterDOMLoaded = concatenateResources(
|
||||||
|
...config.components.map((c) => c.Component.afterDOMLoaded),
|
||||||
|
)
|
||||||
|
Flex.beforeDOMLoaded = concatenateResources(
|
||||||
|
...config.components.map((c) => c.Component.beforeDOMLoaded),
|
||||||
|
)
|
||||||
|
Flex.css = concatenateResources(...config.components.map((c) => c.Component.css))
|
||||||
|
return Flex
|
||||||
|
}) satisfies QuartzComponentConstructor<FlexConfig>
|
@ -18,6 +18,7 @@ export interface D3Config {
|
|||||||
removeTags: string[]
|
removeTags: string[]
|
||||||
showTags: boolean
|
showTags: boolean
|
||||||
focusOnHover?: boolean
|
focusOnHover?: boolean
|
||||||
|
enableRadial?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GraphOptions {
|
interface GraphOptions {
|
||||||
@ -39,6 +40,7 @@ const defaultOptions: GraphOptions = {
|
|||||||
showTags: true,
|
showTags: true,
|
||||||
removeTags: [],
|
removeTags: [],
|
||||||
focusOnHover: false,
|
focusOnHover: false,
|
||||||
|
enableRadial: false,
|
||||||
},
|
},
|
||||||
globalGraph: {
|
globalGraph: {
|
||||||
drag: true,
|
drag: true,
|
||||||
@ -46,17 +48,18 @@ const defaultOptions: GraphOptions = {
|
|||||||
depth: -1,
|
depth: -1,
|
||||||
scale: 0.9,
|
scale: 0.9,
|
||||||
repelForce: 0.5,
|
repelForce: 0.5,
|
||||||
centerForce: 0.3,
|
centerForce: 0.2,
|
||||||
linkDistance: 30,
|
linkDistance: 30,
|
||||||
fontSize: 0.6,
|
fontSize: 0.6,
|
||||||
opacityScale: 1,
|
opacityScale: 1,
|
||||||
showTags: true,
|
showTags: true,
|
||||||
removeTags: [],
|
removeTags: [],
|
||||||
focusOnHover: true,
|
focusOnHover: true,
|
||||||
|
enableRadial: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ((opts?: GraphOptions) => {
|
export default ((opts?: Partial<GraphOptions>) => {
|
||||||
const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||||
const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph }
|
const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph }
|
||||||
const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph }
|
const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph }
|
||||||
@ -64,8 +67,8 @@ export default ((opts?: GraphOptions) => {
|
|||||||
<div class={classNames(displayClass, "graph")}>
|
<div class={classNames(displayClass, "graph")}>
|
||||||
<h3>{i18n(cfg.locale).components.graph.title}</h3>
|
<h3>{i18n(cfg.locale).components.graph.title}</h3>
|
||||||
<div class="graph-outer">
|
<div class="graph-outer">
|
||||||
<div id="graph-container" data-cfg={JSON.stringify(localGraph)}></div>
|
<div class="graph-container" data-cfg={JSON.stringify(localGraph)}></div>
|
||||||
<button id="global-graph-icon" aria-label="Global Graph">
|
<button class="global-graph-icon" aria-label="Global Graph">
|
||||||
<svg
|
<svg
|
||||||
version="1.1"
|
version="1.1"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
@ -92,8 +95,8 @@ export default ((opts?: GraphOptions) => {
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="global-graph-outer">
|
<div class="global-graph-outer">
|
||||||
<div id="global-graph-container" data-cfg={JSON.stringify(globalGraph)}></div>
|
<div class="global-graph-container" data-cfg={JSON.stringify(globalGraph)}></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -1,22 +1,40 @@
|
|||||||
import { i18n } from "../i18n"
|
import { i18n } from "../i18n"
|
||||||
import { FullSlug, joinSegments, pathToRoot } from "../util/path"
|
import { FullSlug, getFileExtension, joinSegments, pathToRoot } from "../util/path"
|
||||||
import { JSResourceToScriptElement } from "../util/resources"
|
import { CSSResourceToStyleElement, JSResourceToScriptElement } from "../util/resources"
|
||||||
import { googleFontHref } from "../util/theme"
|
import { googleFontHref, googleFontSubsetHref } from "../util/theme"
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
|
import { unescapeHTML } from "../util/escape"
|
||||||
|
import { CustomOgImagesEmitterName } from "../plugins/emitters/ogImage"
|
||||||
export default (() => {
|
export default (() => {
|
||||||
const Head: QuartzComponent = ({ cfg, fileData, externalResources }: QuartzComponentProps) => {
|
const Head: QuartzComponent = ({
|
||||||
const title = fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title
|
cfg,
|
||||||
|
fileData,
|
||||||
|
externalResources,
|
||||||
|
ctx,
|
||||||
|
}: QuartzComponentProps) => {
|
||||||
|
const titleSuffix = cfg.pageTitleSuffix ?? ""
|
||||||
|
const title =
|
||||||
|
(fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title) + titleSuffix
|
||||||
const description =
|
const description =
|
||||||
fileData.description?.trim() ?? i18n(cfg.locale).propertyDefaults.description
|
fileData.frontmatter?.socialDescription ??
|
||||||
const { css, js } = externalResources
|
fileData.frontmatter?.description ??
|
||||||
|
unescapeHTML(fileData.description?.trim() ?? i18n(cfg.locale).propertyDefaults.description)
|
||||||
|
|
||||||
|
const { css, js, additionalHead } = externalResources
|
||||||
|
|
||||||
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
||||||
const path = url.pathname as FullSlug
|
const path = url.pathname as FullSlug
|
||||||
const baseDir = fileData.slug === "404" ? path : pathToRoot(fileData.slug!)
|
const baseDir = fileData.slug === "404" ? path : pathToRoot(fileData.slug!)
|
||||||
|
|
||||||
const iconPath = joinSegments(baseDir, "static/icon.png")
|
const iconPath = joinSegments(baseDir, "static/icon.png")
|
||||||
const ogImagePath = `https://${cfg.baseUrl}/static/og-image.png`
|
|
||||||
|
// Url of current page
|
||||||
|
const socialUrl =
|
||||||
|
fileData.slug === "404" ? url.toString() : joinSegments(url.toString(), fileData.slug!)
|
||||||
|
|
||||||
|
const usesCustomOgImage = ctx.cfg.plugins.emitters.some(
|
||||||
|
(e) => e.name === CustomOgImagesEmitterName,
|
||||||
|
)
|
||||||
|
const ogImageDefaultPath = `https://${cfg.baseUrl}/static/og-image.png`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<head>
|
<head>
|
||||||
@ -27,23 +45,58 @@ export default (() => {
|
|||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
||||||
<link rel="stylesheet" href={googleFontHref(cfg.theme)} />
|
<link rel="stylesheet" href={googleFontHref(cfg.theme)} />
|
||||||
|
{cfg.theme.typography.title && (
|
||||||
|
<link rel="stylesheet" href={googleFontSubsetHref(cfg.theme, cfg.pageTitle)} />
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossOrigin="anonymous" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|
||||||
|
<meta name="og:site_name" content={cfg.pageTitle}></meta>
|
||||||
<meta property="og:title" content={title} />
|
<meta property="og:title" content={title} />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
|
<meta name="twitter:title" content={title} />
|
||||||
|
<meta name="twitter:description" content={description} />
|
||||||
<meta property="og:description" content={description} />
|
<meta property="og:description" content={description} />
|
||||||
{cfg.baseUrl && <meta property="og:image" content={ogImagePath} />}
|
<meta property="og:image:alt" content={description} />
|
||||||
<meta property="og:width" content="1200" />
|
|
||||||
<meta property="og:height" content="675" />
|
{!usesCustomOgImage && (
|
||||||
|
<>
|
||||||
|
<meta property="og:image" content={ogImageDefaultPath} />
|
||||||
|
<meta property="og:image:url" content={ogImageDefaultPath} />
|
||||||
|
<meta name="twitter:image" content={ogImageDefaultPath} />
|
||||||
|
<meta
|
||||||
|
property="og:image:type"
|
||||||
|
content={`image/${getFileExtension(ogImageDefaultPath) ?? "png"}`}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{cfg.baseUrl && (
|
||||||
|
<>
|
||||||
|
<meta property="twitter:domain" content={cfg.baseUrl}></meta>
|
||||||
|
<meta property="og:url" content={socialUrl}></meta>
|
||||||
|
<meta property="twitter:url" content={socialUrl}></meta>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<link rel="icon" href={iconPath} />
|
<link rel="icon" href={iconPath} />
|
||||||
<meta name="description" content={description} />
|
<meta name="description" content={description} />
|
||||||
<meta name="generator" content="Quartz" />
|
<meta name="generator" content="Quartz" />
|
||||||
{css.map((href) => (
|
|
||||||
<link key={href} href={href} rel="stylesheet" type="text/css" spa-preserve />
|
{css.map((resource) => CSSResourceToStyleElement(resource, true))}
|
||||||
))}
|
|
||||||
{js
|
{js
|
||||||
.filter((resource) => resource.loadTime === "beforeDOMReady")
|
.filter((resource) => resource.loadTime === "beforeDOMReady")
|
||||||
.map((res) => JSResourceToScriptElement(res, true))}
|
.map((res) => JSResourceToScriptElement(res, true))}
|
||||||
|
{additionalHead.map((resource) => {
|
||||||
|
if (typeof resource === "function") {
|
||||||
|
return resource(fileData)
|
||||||
|
} else {
|
||||||
|
return resource
|
||||||
|
}
|
||||||
|
})}
|
||||||
</head>
|
</head>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
|
|
||||||
export default ((component?: QuartzComponent) => {
|
export default ((component: QuartzComponent) => {
|
||||||
if (component) {
|
const Component = component
|
||||||
const Component = component
|
const MobileOnly: QuartzComponent = (props: QuartzComponentProps) => {
|
||||||
const MobileOnly: QuartzComponent = (props: QuartzComponentProps) => {
|
return <Component displayClass="mobile-only" {...props} />
|
||||||
return <Component displayClass="mobile-only" {...props} />
|
|
||||||
}
|
|
||||||
|
|
||||||
MobileOnly.displayName = component.displayName
|
|
||||||
MobileOnly.afterDOMLoaded = component?.afterDOMLoaded
|
|
||||||
MobileOnly.beforeDOMLoaded = component?.beforeDOMLoaded
|
|
||||||
MobileOnly.css = component?.css
|
|
||||||
return MobileOnly
|
|
||||||
} else {
|
|
||||||
return () => <></>
|
|
||||||
}
|
}
|
||||||
}) satisfies QuartzComponentConstructor
|
|
||||||
|
MobileOnly.displayName = component.displayName
|
||||||
|
MobileOnly.afterDOMLoaded = component?.afterDOMLoaded
|
||||||
|
MobileOnly.beforeDOMLoaded = component?.beforeDOMLoaded
|
||||||
|
MobileOnly.css = component?.css
|
||||||
|
return MobileOnly
|
||||||
|
}) satisfies QuartzComponentConstructor<QuartzComponent>
|
||||||
|
48
quartz/components/OverflowList.tsx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { JSX } from "preact"
|
||||||
|
|
||||||
|
const OverflowList = ({
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: JSX.HTMLAttributes<HTMLUListElement> & { id: string }) => {
|
||||||
|
return (
|
||||||
|
<ul {...props} class={[props.class, "overflow"].filter(Boolean).join(" ")} id={props.id}>
|
||||||
|
{children}
|
||||||
|
<li class="overflow-end" />
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let numExplorers = 0
|
||||||
|
export default () => {
|
||||||
|
const id = `list-${numExplorers++}`
|
||||||
|
|
||||||
|
return {
|
||||||
|
OverflowList: (props: JSX.HTMLAttributes<HTMLUListElement>) => (
|
||||||
|
<OverflowList {...props} id={id} />
|
||||||
|
),
|
||||||
|
overflowListAfterDOMLoaded: `
|
||||||
|
document.addEventListener("nav", (e) => {
|
||||||
|
const observer = new IntersectionObserver((entries) => {
|
||||||
|
for (const entry of entries) {
|
||||||
|
const parentUl = entry.target.parentElement
|
||||||
|
if (!parentUl) return
|
||||||
|
if (entry.isIntersecting) {
|
||||||
|
parentUl.classList.remove("gradient-active")
|
||||||
|
} else {
|
||||||
|
parentUl.classList.add("gradient-active")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const ul = document.getElementById("${id}")
|
||||||
|
if (!ul) return
|
||||||
|
|
||||||
|
const end = ul.querySelector(".overflow-end")
|
||||||
|
if (!end) return
|
||||||
|
|
||||||
|
observer.observe(end)
|
||||||
|
window.addCleanup(() => observer.disconnect())
|
||||||
|
})
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { FullSlug, resolveRelative } from "../util/path"
|
import { FullSlug, isFolderPath, resolveRelative } from "../util/path"
|
||||||
import { QuartzPluginData } from "../plugins/vfile"
|
import { QuartzPluginData } from "../plugins/vfile"
|
||||||
import { Date, getDate } from "./Date"
|
import { Date, getDate } from "./Date"
|
||||||
import { QuartzComponent, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentProps } from "./types"
|
||||||
@ -8,6 +8,33 @@ export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number
|
|||||||
|
|
||||||
export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
|
export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
|
||||||
return (f1, f2) => {
|
return (f1, f2) => {
|
||||||
|
// Sort by date/alphabetical
|
||||||
|
if (f1.dates && f2.dates) {
|
||||||
|
// sort descending
|
||||||
|
return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime()
|
||||||
|
} else if (f1.dates && !f2.dates) {
|
||||||
|
// prioritize files with dates
|
||||||
|
return -1
|
||||||
|
} else if (!f1.dates && f2.dates) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise, sort lexographically by title
|
||||||
|
const f1Title = f1.frontmatter?.title.toLowerCase() ?? ""
|
||||||
|
const f2Title = f2.frontmatter?.title.toLowerCase() ?? ""
|
||||||
|
return f1Title.localeCompare(f2Title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function byDateAndAlphabeticalFolderFirst(cfg: GlobalConfiguration): SortFn {
|
||||||
|
return (f1, f2) => {
|
||||||
|
// Sort folders first
|
||||||
|
const f1IsFolder = isFolderPath(f1.slug ?? "")
|
||||||
|
const f2IsFolder = isFolderPath(f2.slug ?? "")
|
||||||
|
if (f1IsFolder && !f2IsFolder) return -1
|
||||||
|
if (!f1IsFolder && f2IsFolder) return 1
|
||||||
|
|
||||||
|
// If both are folders or both are files, sort by date/alphabetical
|
||||||
if (f1.dates && f2.dates) {
|
if (f1.dates && f2.dates) {
|
||||||
// sort descending
|
// sort descending
|
||||||
return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime()
|
return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime()
|
||||||
@ -31,7 +58,7 @@ type Props = {
|
|||||||
} & QuartzComponentProps
|
} & QuartzComponentProps
|
||||||
|
|
||||||
export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => {
|
export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => {
|
||||||
const sorter = sort ?? byDateAndAlphabetical(cfg)
|
const sorter = sort ?? byDateAndAlphabeticalFolderFirst(cfg)
|
||||||
let list = allFiles.sort(sorter)
|
let list = allFiles.sort(sorter)
|
||||||
if (limit) {
|
if (limit) {
|
||||||
list = list.slice(0, limit)
|
list = list.slice(0, limit)
|
||||||
@ -46,13 +73,9 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort
|
|||||||
return (
|
return (
|
||||||
<li class="section-li">
|
<li class="section-li">
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div>
|
<p class="meta">
|
||||||
{page.dates && (
|
{page.dates && <Date date={getDate(cfg, page)!} locale={cfg.locale} />}
|
||||||
<p class="meta">
|
</p>
|
||||||
<Date date={getDate(cfg, page)!} locale={cfg.locale} />
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div class="desc">
|
<div class="desc">
|
||||||
<h3>
|
<h3>
|
||||||
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">
|
||||||
|
@ -17,6 +17,7 @@ PageTitle.css = `
|
|||||||
.page-title {
|
.page-title {
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
font-family: var(--titleFont);
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
38
quartz/components/ReaderMode.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import readerModeScript from "./scripts/readermode.inline"
|
||||||
|
import styles from "./styles/readermode.scss"
|
||||||
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
|
import { i18n } from "../i18n"
|
||||||
|
import { classNames } from "../util/lang"
|
||||||
|
|
||||||
|
const ReaderMode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||||
|
return (
|
||||||
|
<button class={classNames(displayClass, "readermode")}>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||||
|
version="1.1"
|
||||||
|
class="readerIcon"
|
||||||
|
fill="currentColor"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="0.2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
width="64px"
|
||||||
|
height="64px"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
aria-label={i18n(cfg.locale).components.readerMode.title}
|
||||||
|
>
|
||||||
|
<title>{i18n(cfg.locale).components.readerMode.title}</title>
|
||||||
|
<g transform="translate(-1.8, -1.8) scale(1.15, 1.2)">
|
||||||
|
<path d="M8.9891247,2.5 C10.1384702,2.5 11.2209868,2.96705384 12.0049645,3.76669482 C12.7883914,2.96705384 13.8709081,2.5 15.0202536,2.5 L18.7549359,2.5 C19.1691495,2.5 19.5049359,2.83578644 19.5049359,3.25 L19.5046891,4.004 L21.2546891,4.00457396 C21.6343849,4.00457396 21.9481801,4.28672784 21.9978425,4.6528034 L22.0046891,4.75457396 L22.0046891,20.25 C22.0046891,20.6296958 21.7225353,20.943491 21.3564597,20.9931534 L21.2546891,21 L2.75468914,21 C2.37499337,21 2.06119817,20.7178461 2.01153575,20.3517706 L2.00468914,20.25 L2.00468914,4.75457396 C2.00468914,4.37487819 2.28684302,4.061083 2.65291858,4.01142057 L2.75468914,4.00457396 L4.50368914,4.004 L4.50444233,3.25 C4.50444233,2.87030423 4.78659621,2.55650904 5.15267177,2.50684662 L5.25444233,2.5 L8.9891247,2.5 Z M4.50368914,5.504 L3.50468914,5.504 L3.50468914,19.5 L10.9478955,19.4998273 C10.4513189,18.9207296 9.73864328,18.5588115 8.96709342,18.5065584 L8.77307039,18.5 L5.25444233,18.5 C4.87474657,18.5 4.56095137,18.2178461 4.51128895,17.8517706 L4.50444233,17.75 L4.50368914,5.504 Z M19.5049359,17.75 C19.5049359,18.1642136 19.1691495,18.5 18.7549359,18.5 L15.2363079,18.5 C14.3910149,18.5 13.5994408,18.8724714 13.0614828,19.4998273 L20.5046891,19.5 L20.5046891,5.504 L19.5046891,5.504 L19.5049359,17.75 Z M18.0059359,3.999 L15.0202536,4 L14.8259077,4.00692283 C13.9889509,4.06666544 13.2254227,4.50975805 12.7549359,5.212 L12.7549359,17.777 L12.7782651,17.7601316 C13.4923805,17.2719483 14.3447024,17 15.2363079,17 L18.0059359,16.999 L18.0056891,4.798 L18.0033792,4.75457396 L18.0056891,4.71 L18.0059359,3.999 Z M8.9891247,4 L6.00368914,3.999 L6.00599909,4.75457396 L6.00599909,4.75457396 L6.00368914,4.783 L6.00368914,16.999 L8.77307039,17 C9.57551536,17 10.3461406,17.2202781 11.0128313,17.6202194 L11.2536891,17.776 L11.2536891,5.211 C10.8200889,4.56369974 10.1361548,4.13636104 9.37521067,4.02745763 L9.18347055,4.00692283 L8.9891247,4 Z" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderMode.beforeDOMLoaded = readerModeScript
|
||||||
|
ReaderMode.css = styles
|
||||||
|
|
||||||
|
export default (() => ReaderMode) satisfies QuartzComponentConstructor
|
@ -19,7 +19,7 @@ export default ((userOpts?: Partial<SearchOptions>) => {
|
|||||||
const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder
|
const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder
|
||||||
return (
|
return (
|
||||||
<div class={classNames(displayClass, "search")}>
|
<div class={classNames(displayClass, "search")}>
|
||||||
<button class="search-button" id="search-button">
|
<button class="search-button">
|
||||||
<p>{i18n(cfg.locale).components.search.title}</p>
|
<p>{i18n(cfg.locale).components.search.title}</p>
|
||||||
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7">
|
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7">
|
||||||
<title>Search</title>
|
<title>Search</title>
|
||||||
@ -29,17 +29,17 @@ export default ((userOpts?: Partial<SearchOptions>) => {
|
|||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<div id="search-container">
|
<div class="search-container">
|
||||||
<div id="search-space">
|
<div class="search-space">
|
||||||
<input
|
<input
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
id="search-bar"
|
class="search-bar"
|
||||||
name="search"
|
name="search"
|
||||||
type="text"
|
type="text"
|
||||||
aria-label={searchPlaceholder}
|
aria-label={searchPlaceholder}
|
||||||
placeholder={searchPlaceholder}
|
placeholder={searchPlaceholder}
|
||||||
/>
|
/>
|
||||||
<div id="search-layout" data-preview={opts.enablePreview}></div>
|
<div class="search-layout" data-preview={opts.enablePreview}></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,6 +6,8 @@ import { classNames } from "../util/lang"
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import script from "./scripts/toc.inline"
|
import script from "./scripts/toc.inline"
|
||||||
import { i18n } from "../i18n"
|
import { i18n } from "../i18n"
|
||||||
|
import OverflowListFactory from "./OverflowList"
|
||||||
|
import { concatenateResources } from "../util/resources"
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
layout: "modern" | "legacy"
|
layout: "modern" | "legacy"
|
||||||
@ -15,42 +17,68 @@ const defaultOptions: Options = {
|
|||||||
layout: "modern",
|
layout: "modern",
|
||||||
}
|
}
|
||||||
|
|
||||||
const TableOfContents: QuartzComponent = ({
|
export default ((opts?: Partial<Options>) => {
|
||||||
fileData,
|
const layout = opts?.layout ?? defaultOptions.layout
|
||||||
displayClass,
|
const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory()
|
||||||
cfg,
|
const TableOfContents: QuartzComponent = ({
|
||||||
}: QuartzComponentProps) => {
|
fileData,
|
||||||
if (!fileData.toc) {
|
displayClass,
|
||||||
return null
|
cfg,
|
||||||
|
}: QuartzComponentProps) => {
|
||||||
|
if (!fileData.toc) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={classNames(displayClass, "toc")}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class={fileData.collapseToc ? "collapsed toc-header" : "toc-header"}
|
||||||
|
aria-controls="toc-content"
|
||||||
|
aria-expanded={!fileData.collapseToc}
|
||||||
|
>
|
||||||
|
<h3>{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="fold"
|
||||||
|
>
|
||||||
|
<polyline points="6 9 12 15 18 9"></polyline>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<OverflowList class={fileData.collapseToc ? "collapsed toc-content" : "toc-content"}>
|
||||||
|
{fileData.toc.map((tocEntry) => (
|
||||||
|
<li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
||||||
|
<a href={`#${tocEntry.slug}`} data-for={tocEntry.slug}>
|
||||||
|
{tocEntry.text}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</OverflowList>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
TableOfContents.css = modernStyle
|
||||||
<div class={classNames(displayClass, "toc")}>
|
TableOfContents.afterDOMLoaded = concatenateResources(script, overflowListAfterDOMLoaded)
|
||||||
<button
|
|
||||||
type="button"
|
const LegacyTableOfContents: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => {
|
||||||
id="toc"
|
if (!fileData.toc) {
|
||||||
class={fileData.collapseToc ? "collapsed" : ""}
|
return null
|
||||||
aria-controls="toc-content"
|
}
|
||||||
aria-expanded={!fileData.collapseToc}
|
return (
|
||||||
>
|
<details class="toc" open={!fileData.collapseToc}>
|
||||||
<h3>{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
<summary>
|
||||||
<svg
|
<h3>{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
</summary>
|
||||||
width="24"
|
<ul>
|
||||||
height="24"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="2"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
class="fold"
|
|
||||||
>
|
|
||||||
<polyline points="6 9 12 15 18 9"></polyline>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<div id="toc-content" class={fileData.collapseToc ? "collapsed" : ""}>
|
|
||||||
<ul class="overflow">
|
|
||||||
{fileData.toc.map((tocEntry) => (
|
{fileData.toc.map((tocEntry) => (
|
||||||
<li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
<li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
||||||
<a href={`#${tocEntry.slug}`} data-for={tocEntry.slug}>
|
<a href={`#${tocEntry.slug}`} data-for={tocEntry.slug}>
|
||||||
@ -59,37 +87,10 @@ const TableOfContents: QuartzComponent = ({
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</details>
|
||||||
</div>
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
TableOfContents.css = modernStyle
|
|
||||||
TableOfContents.afterDOMLoaded = script
|
|
||||||
|
|
||||||
const LegacyTableOfContents: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => {
|
|
||||||
if (!fileData.toc) {
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
return (
|
LegacyTableOfContents.css = legacyStyle
|
||||||
<details id="toc" open={!fileData.collapseToc}>
|
|
||||||
<summary>
|
|
||||||
<h3>{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
|
||||||
</summary>
|
|
||||||
<ul>
|
|
||||||
{fileData.toc.map((tocEntry) => (
|
|
||||||
<li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
|
||||||
<a href={`#${tocEntry.slug}`} data-for={tocEntry.slug}>
|
|
||||||
{tocEntry.text}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</details>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
LegacyTableOfContents.css = legacyStyle
|
|
||||||
|
|
||||||
export default ((opts?: Partial<Options>) => {
|
|
||||||
const layout = opts?.layout ?? defaultOptions.layout
|
|
||||||
return layout === "modern" ? TableOfContents : LegacyTableOfContents
|
return layout === "modern" ? TableOfContents : LegacyTableOfContents
|
||||||
}) satisfies QuartzComponentConstructor
|
}) satisfies QuartzComponentConstructor
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import { pathToRoot, slugTag } from "../util/path"
|
import { FullSlug, resolveRelative } from "../util/path"
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
|
|
||||||
const TagList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
const TagList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => {
|
||||||
const tags = fileData.frontmatter?.tags
|
const tags = fileData.frontmatter?.tags
|
||||||
const baseDir = pathToRoot(fileData.slug!)
|
|
||||||
if (tags && tags.length > 0) {
|
if (tags && tags.length > 0) {
|
||||||
return (
|
return (
|
||||||
<ul class={classNames(displayClass, "tags")}>
|
<ul class={classNames(displayClass, "tags")}>
|
||||||
{tags.map((tag) => {
|
{tags.map((tag) => {
|
||||||
const linkDest = baseDir + `/tags/${slugTag(tag)}`
|
const linkDest = resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug)
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<a href={linkDest} class="internal tag-link">
|
<a href={linkDest} class="internal tag-link">
|
||||||
@ -33,7 +32,6 @@ TagList.css = `
|
|||||||
gap: 0.4rem;
|
gap: 0.4rem;
|
||||||
margin: 1rem 0;
|
margin: 1rem 0;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-self: end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-li > .section > .tags {
|
.section-li > .section > .tags {
|
||||||
|
@ -4,6 +4,7 @@ import FolderContent from "./pages/FolderContent"
|
|||||||
import NotFound from "./pages/404"
|
import NotFound from "./pages/404"
|
||||||
import ArticleTitle from "./ArticleTitle"
|
import ArticleTitle from "./ArticleTitle"
|
||||||
import Darkmode from "./Darkmode"
|
import Darkmode from "./Darkmode"
|
||||||
|
import ReaderMode from "./ReaderMode"
|
||||||
import Head from "./Head"
|
import Head from "./Head"
|
||||||
import PageTitle from "./PageTitle"
|
import PageTitle from "./PageTitle"
|
||||||
import ContentMeta from "./ContentMeta"
|
import ContentMeta from "./ContentMeta"
|
||||||
@ -20,6 +21,8 @@ import MobileOnly from "./MobileOnly"
|
|||||||
import RecentNotes from "./RecentNotes"
|
import RecentNotes from "./RecentNotes"
|
||||||
import Breadcrumbs from "./Breadcrumbs"
|
import Breadcrumbs from "./Breadcrumbs"
|
||||||
import Comments from "./Comments"
|
import Comments from "./Comments"
|
||||||
|
import Flex from "./Flex"
|
||||||
|
import ConditionalRender from "./ConditionalRender"
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ArticleTitle,
|
ArticleTitle,
|
||||||
@ -27,6 +30,7 @@ export {
|
|||||||
TagContent,
|
TagContent,
|
||||||
FolderContent,
|
FolderContent,
|
||||||
Darkmode,
|
Darkmode,
|
||||||
|
ReaderMode,
|
||||||
Head,
|
Head,
|
||||||
PageTitle,
|
PageTitle,
|
||||||
ContentMeta,
|
ContentMeta,
|
||||||
@ -44,4 +48,6 @@ export {
|
|||||||
NotFound,
|
NotFound,
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Comments,
|
Comments,
|
||||||
|
Flex,
|
||||||
|
ConditionalRender,
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
import { ComponentChildren } from "preact"
|
||||||
import { htmlToJsx } from "../../util/jsx"
|
import { htmlToJsx } from "../../util/jsx"
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||||
|
|
||||||
const Content: QuartzComponent = ({ fileData, tree }: QuartzComponentProps) => {
|
const Content: QuartzComponent = ({ fileData, tree }: QuartzComponentProps) => {
|
||||||
const content = htmlToJsx(fileData.filePath!, tree)
|
const content = htmlToJsx(fileData.filePath!, tree) as ComponentChildren
|
||||||
const classes: string[] = fileData.frontmatter?.cssclasses ?? []
|
const classes: string[] = fileData.frontmatter?.cssclasses ?? []
|
||||||
const classString = ["popover-hint", ...classes].join(" ")
|
const classString = ["popover-hint", ...classes].join(" ")
|
||||||
return <article class={classString}>{content}</article>
|
return <article class={classString}>{content}</article>
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||||
import path from "path"
|
|
||||||
|
|
||||||
import style from "../styles/listPage.scss"
|
import style from "../styles/listPage.scss"
|
||||||
import { PageList, SortFn } from "../PageList"
|
import { PageList, SortFn } from "../PageList"
|
||||||
import { stripSlashes, simplifySlug } from "../../util/path"
|
|
||||||
import { Root } from "hast"
|
import { Root } from "hast"
|
||||||
import { htmlToJsx } from "../../util/jsx"
|
import { htmlToJsx } from "../../util/jsx"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
|
import { QuartzPluginData } from "../../plugins/vfile"
|
||||||
|
import { ComponentChildren } from "preact"
|
||||||
|
import { concatenateResources } from "../../util/resources"
|
||||||
|
import { trieFromAllFiles } from "../../util/ctx"
|
||||||
|
|
||||||
interface FolderContentOptions {
|
interface FolderContentOptions {
|
||||||
/**
|
/**
|
||||||
* Whether to display number of folders
|
* Whether to display number of folders
|
||||||
*/
|
*/
|
||||||
showFolderCount: boolean
|
showFolderCount: boolean
|
||||||
|
showSubfolders: boolean
|
||||||
sort?: SortFn
|
sort?: SortFn
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: FolderContentOptions = {
|
const defaultOptions: FolderContentOptions = {
|
||||||
showFolderCount: true,
|
showFolderCount: true,
|
||||||
|
showSubfolders: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ((opts?: Partial<FolderContentOptions>) => {
|
export default ((opts?: Partial<FolderContentOptions>) => {
|
||||||
@ -25,31 +29,82 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||||||
|
|
||||||
const FolderContent: QuartzComponent = (props: QuartzComponentProps) => {
|
const FolderContent: QuartzComponent = (props: QuartzComponentProps) => {
|
||||||
const { tree, fileData, allFiles, cfg } = props
|
const { tree, fileData, allFiles, cfg } = props
|
||||||
const folderSlug = stripSlashes(simplifySlug(fileData.slug!))
|
|
||||||
const allPagesInFolder = allFiles.filter((file) => {
|
const trie = (props.ctx.trie ??= trieFromAllFiles(allFiles))
|
||||||
const fileSlug = stripSlashes(simplifySlug(file.slug!))
|
const folder = trie.findNode(fileData.slug!.split("/"))
|
||||||
const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug
|
if (!folder) {
|
||||||
const folderParts = folderSlug.split(path.posix.sep)
|
return null
|
||||||
const fileParts = fileSlug.split(path.posix.sep)
|
}
|
||||||
const isDirectChild = fileParts.length === folderParts.length + 1
|
|
||||||
return prefixed && isDirectChild
|
const allPagesInFolder: QuartzPluginData[] =
|
||||||
})
|
folder.children
|
||||||
|
.map((node) => {
|
||||||
|
// regular file, proceed
|
||||||
|
if (node.data) {
|
||||||
|
return node.data
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.isFolder && options.showSubfolders) {
|
||||||
|
// folders that dont have data need synthetic files
|
||||||
|
const getMostRecentDates = (): QuartzPluginData["dates"] => {
|
||||||
|
let maybeDates: QuartzPluginData["dates"] | undefined = undefined
|
||||||
|
for (const child of node.children) {
|
||||||
|
if (child.data?.dates) {
|
||||||
|
// compare all dates and assign to maybeDates if its more recent or its not set
|
||||||
|
if (!maybeDates) {
|
||||||
|
maybeDates = { ...child.data.dates }
|
||||||
|
} else {
|
||||||
|
if (child.data.dates.created > maybeDates.created) {
|
||||||
|
maybeDates.created = child.data.dates.created
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.data.dates.modified > maybeDates.modified) {
|
||||||
|
maybeDates.modified = child.data.dates.modified
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.data.dates.published > maybeDates.published) {
|
||||||
|
maybeDates.published = child.data.dates.published
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
maybeDates ?? {
|
||||||
|
created: new Date(),
|
||||||
|
modified: new Date(),
|
||||||
|
published: new Date(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
slug: node.slug,
|
||||||
|
dates: getMostRecentDates(),
|
||||||
|
frontmatter: {
|
||||||
|
title: node.displayName,
|
||||||
|
tags: [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter((page) => page !== undefined) ?? []
|
||||||
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
|
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
|
||||||
const classes = ["popover-hint", ...cssClasses].join(" ")
|
const classes = cssClasses.join(" ")
|
||||||
const listProps = {
|
const listProps = {
|
||||||
...props,
|
...props,
|
||||||
sort: options.sort,
|
sort: options.sort,
|
||||||
allFiles: allPagesInFolder,
|
allFiles: allPagesInFolder,
|
||||||
}
|
}
|
||||||
|
|
||||||
const content =
|
const content = (
|
||||||
(tree as Root).children.length === 0
|
(tree as Root).children.length === 0
|
||||||
? fileData.description
|
? fileData.description
|
||||||
: htmlToJsx(fileData.filePath!, tree)
|
: htmlToJsx(fileData.filePath!, tree)
|
||||||
|
) as ComponentChildren
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={classes}>
|
<div class="popover-hint">
|
||||||
<article>{content}</article>
|
<article class={classes}>{content}</article>
|
||||||
<div class="page-listing">
|
<div class="page-listing">
|
||||||
{options.showFolderCount && (
|
{options.showFolderCount && (
|
||||||
<p>
|
<p>
|
||||||
@ -66,6 +121,6 @@ export default ((opts?: Partial<FolderContentOptions>) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderContent.css = style + PageList.css
|
FolderContent.css = concatenateResources(style, PageList.css)
|
||||||
return FolderContent
|
return FolderContent
|
||||||
}) satisfies QuartzComponentConstructor
|
}) satisfies QuartzComponentConstructor
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||||
import style from "../styles/listPage.scss"
|
import style from "../styles/listPage.scss"
|
||||||
import { PageList, SortFn } from "../PageList"
|
import { PageList, SortFn } from "../PageList"
|
||||||
import { FullSlug, getAllSegmentPrefixes, simplifySlug } from "../../util/path"
|
import { FullSlug, getAllSegmentPrefixes, resolveRelative, simplifySlug } from "../../util/path"
|
||||||
import { QuartzPluginData } from "../../plugins/vfile"
|
import { QuartzPluginData } from "../../plugins/vfile"
|
||||||
import { Root } from "hast"
|
import { Root } from "hast"
|
||||||
import { htmlToJsx } from "../../util/jsx"
|
import { htmlToJsx } from "../../util/jsx"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
|
import { ComponentChildren } from "preact"
|
||||||
|
import { concatenateResources } from "../../util/resources"
|
||||||
|
|
||||||
interface TagContentOptions {
|
interface TagContentOptions {
|
||||||
sort?: SortFn
|
sort?: SortFn
|
||||||
@ -33,12 +35,13 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
|||||||
(file.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes).includes(tag),
|
(file.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes).includes(tag),
|
||||||
)
|
)
|
||||||
|
|
||||||
const content =
|
const content = (
|
||||||
(tree as Root).children.length === 0
|
(tree as Root).children.length === 0
|
||||||
? fileData.description
|
? fileData.description
|
||||||
: htmlToJsx(fileData.filePath!, tree)
|
: htmlToJsx(fileData.filePath!, tree)
|
||||||
|
) as ComponentChildren
|
||||||
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
|
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
|
||||||
const classes = ["popover-hint", ...cssClasses].join(" ")
|
const classes = cssClasses.join(" ")
|
||||||
if (tag === "/") {
|
if (tag === "/") {
|
||||||
const tags = [
|
const tags = [
|
||||||
...new Set(
|
...new Set(
|
||||||
@ -50,8 +53,8 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
|||||||
tagItemMap.set(tag, allPagesWithTag(tag))
|
tagItemMap.set(tag, allPagesWithTag(tag))
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div class={classes}>
|
<div class="popover-hint">
|
||||||
<article>
|
<article class={classes}>
|
||||||
<p>{content}</p>
|
<p>{content}</p>
|
||||||
</article>
|
</article>
|
||||||
<p>{i18n(cfg.locale).pages.tagContent.totalTags({ count: tags.length })}</p>
|
<p>{i18n(cfg.locale).pages.tagContent.totalTags({ count: tags.length })}</p>
|
||||||
@ -71,10 +74,13 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
|||||||
? contentPage?.description
|
? contentPage?.description
|
||||||
: htmlToJsx(contentPage.filePath!, root)
|
: htmlToJsx(contentPage.filePath!, root)
|
||||||
|
|
||||||
|
const tagListingPage = `/tags/${tag}` as FullSlug
|
||||||
|
const href = resolveRelative(fileData.slug!, tagListingPage)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>
|
<h2>
|
||||||
<a class="internal tag-link" href={`../tags/${tag}`}>
|
<a class="internal tag-link" href={href}>
|
||||||
{tag}
|
{tag}
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
@ -93,7 +99,7 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<PageList limit={options.numPages} {...listProps} sort={opts?.sort} />
|
<PageList limit={options.numPages} {...listProps} sort={options?.sort} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@ -109,12 +115,12 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={classes}>
|
<div class="popover-hint">
|
||||||
<article>{content}</article>
|
<article class={classes}>{content}</article>
|
||||||
<div class="page-listing">
|
<div class="page-listing">
|
||||||
<p>{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}</p>
|
<p>{i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}</p>
|
||||||
<div>
|
<div>
|
||||||
<PageList {...listProps} />
|
<PageList {...listProps} sort={options?.sort} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -122,6 +128,6 @@ export default ((opts?: Partial<TagContentOptions>) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TagContent.css = style + PageList.css
|
TagContent.css = concatenateResources(style, PageList.css)
|
||||||
return TagContent
|
return TagContent
|
||||||
}) satisfies QuartzComponentConstructor
|
}) satisfies QuartzComponentConstructor
|
||||||
|
@ -3,7 +3,8 @@ import { QuartzComponent, QuartzComponentProps } from "./types"
|
|||||||
import HeaderConstructor from "./Header"
|
import HeaderConstructor from "./Header"
|
||||||
import BodyConstructor from "./Body"
|
import BodyConstructor from "./Body"
|
||||||
import { JSResourceToScriptElement, StaticResources } from "../util/resources"
|
import { JSResourceToScriptElement, StaticResources } from "../util/resources"
|
||||||
import { clone, FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
|
import { FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
|
||||||
|
import { clone } from "../util/clone"
|
||||||
import { visit } from "unist-util-visit"
|
import { visit } from "unist-util-visit"
|
||||||
import { Root, Element, ElementContent } from "hast"
|
import { Root, Element, ElementContent } from "hast"
|
||||||
import { GlobalConfiguration } from "../cfg"
|
import { GlobalConfiguration } from "../cfg"
|
||||||
@ -28,8 +29,13 @@ export function pageResources(
|
|||||||
const contentIndexPath = joinSegments(baseDir, "static/contentIndex.json")
|
const contentIndexPath = joinSegments(baseDir, "static/contentIndex.json")
|
||||||
const contentIndexScript = `const fetchData = fetch("${contentIndexPath}").then(data => data.json())`
|
const contentIndexScript = `const fetchData = fetch("${contentIndexPath}").then(data => data.json())`
|
||||||
|
|
||||||
return {
|
const resources: StaticResources = {
|
||||||
css: [joinSegments(baseDir, "index.css"), ...staticResources.css],
|
css: [
|
||||||
|
{
|
||||||
|
content: joinSegments(baseDir, "index.css"),
|
||||||
|
},
|
||||||
|
...staticResources.css,
|
||||||
|
],
|
||||||
js: [
|
js: [
|
||||||
{
|
{
|
||||||
src: joinSegments(baseDir, "prescript.js"),
|
src: joinSegments(baseDir, "prescript.js"),
|
||||||
@ -43,34 +49,33 @@ export function pageResources(
|
|||||||
script: contentIndexScript,
|
script: contentIndexScript,
|
||||||
},
|
},
|
||||||
...staticResources.js,
|
...staticResources.js,
|
||||||
{
|
|
||||||
src: joinSegments(baseDir, "postscript.js"),
|
|
||||||
loadTime: "afterDOMReady",
|
|
||||||
moduleType: "module",
|
|
||||||
contentType: "external",
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
|
additionalHead: staticResources.additionalHead,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources.js.push({
|
||||||
|
src: joinSegments(baseDir, "postscript.js"),
|
||||||
|
loadTime: "afterDOMReady",
|
||||||
|
moduleType: "module",
|
||||||
|
contentType: "external",
|
||||||
|
})
|
||||||
|
|
||||||
|
return resources
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderPage(
|
function renderTranscludes(
|
||||||
|
root: Root,
|
||||||
cfg: GlobalConfiguration,
|
cfg: GlobalConfiguration,
|
||||||
slug: FullSlug,
|
slug: FullSlug,
|
||||||
componentData: QuartzComponentProps,
|
componentData: QuartzComponentProps,
|
||||||
components: RenderComponents,
|
) {
|
||||||
pageResources: StaticResources,
|
|
||||||
): string {
|
|
||||||
// make a deep copy of the tree so we don't remove the transclusion references
|
|
||||||
// for the file cached in contentMap in build.ts
|
|
||||||
const root = clone(componentData.tree) as Root
|
|
||||||
|
|
||||||
// process transcludes in componentData
|
// process transcludes in componentData
|
||||||
visit(root, "element", (node, _index, _parent) => {
|
visit(root, "element", (node, _index, _parent) => {
|
||||||
if (node.tagName === "blockquote") {
|
if (node.tagName === "blockquote") {
|
||||||
const classNames = (node.properties?.className ?? []) as string[]
|
const classNames = (node.properties?.className ?? []) as string[]
|
||||||
if (classNames.includes("transclude")) {
|
if (classNames.includes("transclude")) {
|
||||||
const inner = node.children[0] as Element
|
const inner = node.children[0] as Element
|
||||||
const transcludeTarget = inner.properties["data-slug"] as FullSlug
|
const transcludeTarget = (inner.properties["data-slug"] ?? slug) as FullSlug
|
||||||
const page = componentData.allFiles.find((f) => f.slug === transcludeTarget)
|
const page = componentData.allFiles.find((f) => f.slug === transcludeTarget)
|
||||||
if (!page) {
|
if (!page) {
|
||||||
return
|
return
|
||||||
@ -179,6 +184,19 @@ export function renderPage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderPage(
|
||||||
|
cfg: GlobalConfiguration,
|
||||||
|
slug: FullSlug,
|
||||||
|
componentData: QuartzComponentProps,
|
||||||
|
components: RenderComponents,
|
||||||
|
pageResources: StaticResources,
|
||||||
|
): string {
|
||||||
|
// make a deep copy of the tree so we don't remove the transclusion references
|
||||||
|
// for the file cached in contentMap in build.ts
|
||||||
|
const root = clone(componentData.tree) as Root
|
||||||
|
renderTranscludes(root, cfg, slug, componentData)
|
||||||
|
|
||||||
// set componentData.tree to the edited html that has transclusions rendered
|
// set componentData.tree to the edited html that has transclusions rendered
|
||||||
componentData.tree = root
|
componentData.tree = root
|
||||||
@ -242,8 +260,8 @@ export function renderPage(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{RightComponent}
|
{RightComponent}
|
||||||
|
<Footer {...componentData} />
|
||||||
</Body>
|
</Body>
|
||||||
<Footer {...componentData} />
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
{pageResources.js
|
{pageResources.js
|
||||||
|
@ -1,25 +1,10 @@
|
|||||||
function toggleCallout(this: HTMLElement) {
|
function toggleCallout(this: HTMLElement) {
|
||||||
const outerBlock = this.parentElement!
|
const outerBlock = this.parentElement!
|
||||||
outerBlock.classList.toggle("is-collapsed")
|
outerBlock.classList.toggle("is-collapsed")
|
||||||
|
const content = outerBlock.getElementsByClassName("callout-content")[0] as HTMLElement
|
||||||
|
if (!content) return
|
||||||
const collapsed = outerBlock.classList.contains("is-collapsed")
|
const collapsed = outerBlock.classList.contains("is-collapsed")
|
||||||
const height = collapsed ? this.scrollHeight : outerBlock.scrollHeight
|
content.style.gridTemplateRows = collapsed ? "0fr" : "1fr"
|
||||||
outerBlock.style.maxHeight = height + "px"
|
|
||||||
|
|
||||||
// walk and adjust height of all parents
|
|
||||||
let current = outerBlock
|
|
||||||
let parent = outerBlock.parentElement
|
|
||||||
while (parent) {
|
|
||||||
if (!parent.classList.contains("callout")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const collapsed = parent.classList.contains("is-collapsed")
|
|
||||||
const height = collapsed ? parent.scrollHeight : parent.scrollHeight + current.scrollHeight
|
|
||||||
parent.style.maxHeight = height + "px"
|
|
||||||
|
|
||||||
current = parent
|
|
||||||
parent = parent.parentElement
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupCallout() {
|
function setupCallout() {
|
||||||
@ -27,18 +12,16 @@ function setupCallout() {
|
|||||||
`callout is-collapsible`,
|
`callout is-collapsible`,
|
||||||
) as HTMLCollectionOf<HTMLElement>
|
) as HTMLCollectionOf<HTMLElement>
|
||||||
for (const div of collapsible) {
|
for (const div of collapsible) {
|
||||||
const title = div.firstElementChild
|
const title = div.getElementsByClassName("callout-title")[0] as HTMLElement
|
||||||
|
const content = div.getElementsByClassName("callout-content")[0] as HTMLElement
|
||||||
|
if (!title || !content) continue
|
||||||
|
|
||||||
if (title) {
|
title.addEventListener("click", toggleCallout)
|
||||||
title.addEventListener("click", toggleCallout)
|
window.addCleanup(() => title.removeEventListener("click", toggleCallout))
|
||||||
window.addCleanup(() => title.removeEventListener("click", toggleCallout))
|
|
||||||
|
|
||||||
const collapsed = div.classList.contains("is-collapsed")
|
const collapsed = div.classList.contains("is-collapsed")
|
||||||
const height = collapsed ? title.scrollHeight : div.scrollHeight
|
content.style.gridTemplateRows = collapsed ? "0fr" : "1fr"
|
||||||
div.style.maxHeight = height + "px"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", setupCallout)
|
document.addEventListener("nav", setupCallout)
|
||||||
window.addEventListener("resize", setupCallout)
|
|
||||||
|
@ -8,7 +8,9 @@ document.addEventListener("nav", () => {
|
|||||||
for (let i = 0; i < els.length; i++) {
|
for (let i = 0; i < els.length; i++) {
|
||||||
const codeBlock = els[i].getElementsByTagName("code")[0]
|
const codeBlock = els[i].getElementsByTagName("code")[0]
|
||||||
if (codeBlock) {
|
if (codeBlock) {
|
||||||
const source = codeBlock.innerText.replace(/\n\n/g, "\n")
|
const source = (
|
||||||
|
codeBlock.dataset.clipboard ? JSON.parse(codeBlock.dataset.clipboard) : codeBlock.innerText
|
||||||
|
).replace(/\n\n/g, "\n")
|
||||||
const button = document.createElement("button")
|
const button = document.createElement("button")
|
||||||
button.className = "clipboard-button"
|
button.className = "clipboard-button"
|
||||||
button.type = "button"
|
button.type = "button"
|
||||||
|
@ -13,7 +13,7 @@ const changeTheme = (e: CustomEventMap["themechange"]) => {
|
|||||||
{
|
{
|
||||||
giscus: {
|
giscus: {
|
||||||
setConfig: {
|
setConfig: {
|
||||||
theme: theme,
|
theme: getThemeUrl(getThemeName(theme)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -21,12 +21,36 @@ const changeTheme = (e: CustomEventMap["themechange"]) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getThemeName = (theme: string) => {
|
||||||
|
if (theme !== "dark" && theme !== "light") {
|
||||||
|
return theme
|
||||||
|
}
|
||||||
|
const giscusContainer = document.querySelector(".giscus") as GiscusElement
|
||||||
|
if (!giscusContainer) {
|
||||||
|
return theme
|
||||||
|
}
|
||||||
|
const darkGiscus = giscusContainer.dataset.darkTheme ?? "dark"
|
||||||
|
const lightGiscus = giscusContainer.dataset.lightTheme ?? "light"
|
||||||
|
return theme === "dark" ? darkGiscus : lightGiscus
|
||||||
|
}
|
||||||
|
|
||||||
|
const getThemeUrl = (theme: string) => {
|
||||||
|
const giscusContainer = document.querySelector(".giscus") as GiscusElement
|
||||||
|
if (!giscusContainer) {
|
||||||
|
return `https://giscus.app/themes/${theme}.css`
|
||||||
|
}
|
||||||
|
return `${giscusContainer.dataset.themeUrl ?? "https://giscus.app/themes"}/${theme}.css`
|
||||||
|
}
|
||||||
|
|
||||||
type GiscusElement = Omit<HTMLElement, "dataset"> & {
|
type GiscusElement = Omit<HTMLElement, "dataset"> & {
|
||||||
dataset: DOMStringMap & {
|
dataset: DOMStringMap & {
|
||||||
repo: `${string}/${string}`
|
repo: `${string}/${string}`
|
||||||
repoId: string
|
repoId: string
|
||||||
category: string
|
category: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
themeUrl: string
|
||||||
|
lightTheme: string
|
||||||
|
darkTheme: string
|
||||||
mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname"
|
||||||
strict: string
|
strict: string
|
||||||
reactionsEnabled: string
|
reactionsEnabled: string
|
||||||
@ -57,7 +81,7 @@ document.addEventListener("nav", () => {
|
|||||||
|
|
||||||
const theme = document.documentElement.getAttribute("saved-theme")
|
const theme = document.documentElement.getAttribute("saved-theme")
|
||||||
if (theme) {
|
if (theme) {
|
||||||
giscusScript.setAttribute("data-theme", theme)
|
giscusScript.setAttribute("data-theme", getThemeUrl(getThemeName(theme)))
|
||||||
}
|
}
|
||||||
|
|
||||||
giscusContainer.appendChild(giscusScript)
|
giscusContainer.appendChild(giscusScript)
|
||||||
|
@ -10,7 +10,7 @@ const emitThemeChangeEvent = (theme: "light" | "dark") => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
const switchTheme = (e: Event) => {
|
const switchTheme = () => {
|
||||||
const newTheme =
|
const newTheme =
|
||||||
document.documentElement.getAttribute("saved-theme") === "dark" ? "light" : "dark"
|
document.documentElement.getAttribute("saved-theme") === "dark" ? "light" : "dark"
|
||||||
document.documentElement.setAttribute("saved-theme", newTheme)
|
document.documentElement.setAttribute("saved-theme", newTheme)
|
||||||
@ -25,10 +25,10 @@ document.addEventListener("nav", () => {
|
|||||||
emitThemeChangeEvent(newTheme)
|
emitThemeChangeEvent(newTheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Darkmode toggle
|
for (const darkmodeButton of document.getElementsByClassName("darkmode")) {
|
||||||
const themeButton = document.querySelector("#darkmode") as HTMLButtonElement
|
darkmodeButton.addEventListener("click", switchTheme)
|
||||||
themeButton.addEventListener("click", switchTheme)
|
window.addCleanup(() => darkmodeButton.removeEventListener("click", switchTheme))
|
||||||
window.addCleanup(() => themeButton.removeEventListener("click", switchTheme))
|
}
|
||||||
|
|
||||||
// Listen for changes in prefers-color-scheme
|
// Listen for changes in prefers-color-scheme
|
||||||
const colorSchemeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)")
|
const colorSchemeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)")
|
||||||
|
@ -1,31 +1,40 @@
|
|||||||
import { FolderState } from "../ExplorerNode"
|
import { FileTrieNode } from "../../util/fileTrie"
|
||||||
|
import { FullSlug, resolveRelative, simplifySlug } from "../../util/path"
|
||||||
|
import { ContentDetails } from "../../plugins/emitters/contentIndex"
|
||||||
|
|
||||||
type MaybeHTMLElement = HTMLElement | undefined
|
type MaybeHTMLElement = HTMLElement | undefined
|
||||||
let currentExplorerState: FolderState[]
|
|
||||||
const observer = new IntersectionObserver((entries) => {
|
|
||||||
// If last element is observed, remove gradient of "overflow" class so element is visible
|
|
||||||
const explorerUl = document.getElementById("explorer-ul")
|
|
||||||
if (!explorerUl) return
|
|
||||||
for (const entry of entries) {
|
|
||||||
if (entry.isIntersecting) {
|
|
||||||
explorerUl.classList.add("no-background")
|
|
||||||
} else {
|
|
||||||
explorerUl.classList.remove("no-background")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
interface ParsedOptions {
|
||||||
|
folderClickBehavior: "collapse" | "link"
|
||||||
|
folderDefaultState: "collapsed" | "open"
|
||||||
|
useSavedState: boolean
|
||||||
|
sortFn: (a: FileTrieNode, b: FileTrieNode) => number
|
||||||
|
filterFn: (node: FileTrieNode) => boolean
|
||||||
|
mapFn: (node: FileTrieNode) => void
|
||||||
|
order: "sort" | "filter" | "map"[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type FolderState = {
|
||||||
|
path: string
|
||||||
|
collapsed: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentExplorerState: Array<FolderState>
|
||||||
function toggleExplorer(this: HTMLElement) {
|
function toggleExplorer(this: HTMLElement) {
|
||||||
this.classList.toggle("collapsed")
|
const nearestExplorer = this.closest(".explorer") as HTMLElement
|
||||||
this.setAttribute(
|
if (!nearestExplorer) return
|
||||||
|
const explorerCollapsed = nearestExplorer.classList.toggle("collapsed")
|
||||||
|
nearestExplorer.setAttribute(
|
||||||
"aria-expanded",
|
"aria-expanded",
|
||||||
this.getAttribute("aria-expanded") === "true" ? "false" : "true",
|
nearestExplorer.getAttribute("aria-expanded") === "true" ? "false" : "true",
|
||||||
)
|
)
|
||||||
const content = this.nextElementSibling as MaybeHTMLElement
|
|
||||||
if (!content) return
|
|
||||||
|
|
||||||
content.classList.toggle("collapsed")
|
if (!explorerCollapsed) {
|
||||||
content.style.maxHeight = content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
|
// Stop <html> from being scrollable when mobile explorer is open
|
||||||
|
document.documentElement.classList.add("mobile-no-scroll")
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove("mobile-no-scroll")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleFolder(evt: MouseEvent) {
|
function toggleFolder(evt: MouseEvent) {
|
||||||
@ -33,104 +42,260 @@ function toggleFolder(evt: MouseEvent) {
|
|||||||
const target = evt.target as MaybeHTMLElement
|
const target = evt.target as MaybeHTMLElement
|
||||||
if (!target) return
|
if (!target) return
|
||||||
|
|
||||||
|
// Check if target was svg icon or button
|
||||||
const isSvg = target.nodeName === "svg"
|
const isSvg = target.nodeName === "svg"
|
||||||
const childFolderContainer = (
|
|
||||||
|
// corresponding <ul> element relative to clicked button/folder
|
||||||
|
const folderContainer = (
|
||||||
isSvg
|
isSvg
|
||||||
? target.parentElement?.nextSibling
|
? // svg -> div.folder-container
|
||||||
: target.parentElement?.parentElement?.nextElementSibling
|
target.parentElement
|
||||||
|
: // button.folder-button -> div -> div.folder-container
|
||||||
|
target.parentElement?.parentElement
|
||||||
) as MaybeHTMLElement
|
) as MaybeHTMLElement
|
||||||
const currentFolderParent = (
|
if (!folderContainer) return
|
||||||
isSvg ? target.nextElementSibling : target.parentElement
|
const childFolderContainer = folderContainer.nextElementSibling as MaybeHTMLElement
|
||||||
) as MaybeHTMLElement
|
if (!childFolderContainer) return
|
||||||
if (!(childFolderContainer && currentFolderParent)) return
|
|
||||||
|
|
||||||
childFolderContainer.classList.toggle("open")
|
childFolderContainer.classList.toggle("open")
|
||||||
const isCollapsed = childFolderContainer.classList.contains("open")
|
|
||||||
setFolderState(childFolderContainer, !isCollapsed)
|
// Collapse folder container
|
||||||
const fullFolderPath = currentFolderParent.dataset.folderpath as string
|
const isCollapsed = !childFolderContainer.classList.contains("open")
|
||||||
toggleCollapsedByPath(currentExplorerState, fullFolderPath)
|
setFolderState(childFolderContainer, isCollapsed)
|
||||||
|
|
||||||
|
const currentFolderState = currentExplorerState.find(
|
||||||
|
(item) => item.path === folderContainer.dataset.folderpath,
|
||||||
|
)
|
||||||
|
if (currentFolderState) {
|
||||||
|
currentFolderState.collapsed = isCollapsed
|
||||||
|
} else {
|
||||||
|
currentExplorerState.push({
|
||||||
|
path: folderContainer.dataset.folderpath as FullSlug,
|
||||||
|
collapsed: isCollapsed,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const stringifiedFileTree = JSON.stringify(currentExplorerState)
|
const stringifiedFileTree = JSON.stringify(currentExplorerState)
|
||||||
localStorage.setItem("fileTree", stringifiedFileTree)
|
localStorage.setItem("fileTree", stringifiedFileTree)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupExplorer() {
|
function createFileNode(currentSlug: FullSlug, node: FileTrieNode): HTMLLIElement {
|
||||||
const explorer = document.getElementById("explorer")
|
const template = document.getElementById("template-file") as HTMLTemplateElement
|
||||||
if (!explorer) return
|
const clone = template.content.cloneNode(true) as DocumentFragment
|
||||||
|
const li = clone.querySelector("li") as HTMLLIElement
|
||||||
|
const a = li.querySelector("a") as HTMLAnchorElement
|
||||||
|
a.href = resolveRelative(currentSlug, node.slug)
|
||||||
|
a.dataset.for = node.slug
|
||||||
|
a.textContent = node.displayName
|
||||||
|
|
||||||
if (explorer.dataset.behavior === "collapse") {
|
if (currentSlug === node.slug) {
|
||||||
for (const item of document.getElementsByClassName(
|
a.classList.add("active")
|
||||||
"folder-button",
|
|
||||||
) as HTMLCollectionOf<HTMLElement>) {
|
|
||||||
item.addEventListener("click", toggleFolder)
|
|
||||||
window.addCleanup(() => item.removeEventListener("click", toggleFolder))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
explorer.addEventListener("click", toggleExplorer)
|
return li
|
||||||
window.addCleanup(() => explorer.removeEventListener("click", toggleExplorer))
|
|
||||||
|
|
||||||
// Set up click handlers for each folder (click handler on folder "icon")
|
|
||||||
for (const item of document.getElementsByClassName(
|
|
||||||
"folder-icon",
|
|
||||||
) as HTMLCollectionOf<HTMLElement>) {
|
|
||||||
item.addEventListener("click", toggleFolder)
|
|
||||||
window.addCleanup(() => item.removeEventListener("click", toggleFolder))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get folder state from local storage
|
|
||||||
const storageTree = localStorage.getItem("fileTree")
|
|
||||||
const useSavedFolderState = explorer?.dataset.savestate === "true"
|
|
||||||
const oldExplorerState: FolderState[] =
|
|
||||||
storageTree && useSavedFolderState ? JSON.parse(storageTree) : []
|
|
||||||
const oldIndex = new Map(oldExplorerState.map((entry) => [entry.path, entry.collapsed]))
|
|
||||||
const newExplorerState: FolderState[] = explorer.dataset.tree
|
|
||||||
? JSON.parse(explorer.dataset.tree)
|
|
||||||
: []
|
|
||||||
currentExplorerState = []
|
|
||||||
for (const { path, collapsed } of newExplorerState) {
|
|
||||||
currentExplorerState.push({ path, collapsed: oldIndex.get(path) ?? collapsed })
|
|
||||||
}
|
|
||||||
|
|
||||||
currentExplorerState.map((folderState) => {
|
|
||||||
const folderLi = document.querySelector(
|
|
||||||
`[data-folderpath='${folderState.path}']`,
|
|
||||||
) as MaybeHTMLElement
|
|
||||||
const folderUl = folderLi?.parentElement?.nextElementSibling as MaybeHTMLElement
|
|
||||||
if (folderUl) {
|
|
||||||
setFolderState(folderUl, folderState.collapsed)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("resize", setupExplorer)
|
function createFolderNode(
|
||||||
document.addEventListener("nav", () => {
|
currentSlug: FullSlug,
|
||||||
setupExplorer()
|
node: FileTrieNode,
|
||||||
observer.disconnect()
|
opts: ParsedOptions,
|
||||||
|
): HTMLLIElement {
|
||||||
|
const template = document.getElementById("template-folder") as HTMLTemplateElement
|
||||||
|
const clone = template.content.cloneNode(true) as DocumentFragment
|
||||||
|
const li = clone.querySelector("li") as HTMLLIElement
|
||||||
|
const folderContainer = li.querySelector(".folder-container") as HTMLElement
|
||||||
|
const titleContainer = folderContainer.querySelector("div") as HTMLElement
|
||||||
|
const folderOuter = li.querySelector(".folder-outer") as HTMLElement
|
||||||
|
const ul = folderOuter.querySelector("ul") as HTMLUListElement
|
||||||
|
|
||||||
// select pseudo element at end of list
|
const folderPath = node.slug
|
||||||
const lastItem = document.getElementById("explorer-end")
|
folderContainer.dataset.folderpath = folderPath
|
||||||
if (lastItem) {
|
|
||||||
observer.observe(lastItem)
|
if (opts.folderClickBehavior === "link") {
|
||||||
|
// Replace button with link for link behavior
|
||||||
|
const button = titleContainer.querySelector(".folder-button") as HTMLElement
|
||||||
|
const a = document.createElement("a")
|
||||||
|
a.href = resolveRelative(currentSlug, folderPath)
|
||||||
|
a.dataset.for = folderPath
|
||||||
|
a.className = "folder-title"
|
||||||
|
a.textContent = node.displayName
|
||||||
|
button.replaceWith(a)
|
||||||
|
} else {
|
||||||
|
const span = titleContainer.querySelector(".folder-title") as HTMLElement
|
||||||
|
span.textContent = node.displayName
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the saved state is collapsed or the default state is collapsed
|
||||||
|
const isCollapsed =
|
||||||
|
currentExplorerState.find((item) => item.path === folderPath)?.collapsed ??
|
||||||
|
opts.folderDefaultState === "collapsed"
|
||||||
|
|
||||||
|
// if this folder is a prefix of the current path we
|
||||||
|
// want to open it anyways
|
||||||
|
const simpleFolderPath = simplifySlug(folderPath)
|
||||||
|
const folderIsPrefixOfCurrentSlug =
|
||||||
|
simpleFolderPath === currentSlug.slice(0, simpleFolderPath.length)
|
||||||
|
|
||||||
|
if (!isCollapsed || folderIsPrefixOfCurrentSlug) {
|
||||||
|
folderOuter.classList.add("open")
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const child of node.children) {
|
||||||
|
const childNode = child.isFolder
|
||||||
|
? createFolderNode(currentSlug, child, opts)
|
||||||
|
: createFileNode(currentSlug, child)
|
||||||
|
ul.appendChild(childNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return li
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupExplorer(currentSlug: FullSlug) {
|
||||||
|
const allExplorers = document.querySelectorAll("div.explorer") as NodeListOf<HTMLElement>
|
||||||
|
|
||||||
|
for (const explorer of allExplorers) {
|
||||||
|
const dataFns = JSON.parse(explorer.dataset.dataFns || "{}")
|
||||||
|
const opts: ParsedOptions = {
|
||||||
|
folderClickBehavior: (explorer.dataset.behavior || "collapse") as "collapse" | "link",
|
||||||
|
folderDefaultState: (explorer.dataset.collapsed || "collapsed") as "collapsed" | "open",
|
||||||
|
useSavedState: explorer.dataset.savestate === "true",
|
||||||
|
order: dataFns.order || ["filter", "map", "sort"],
|
||||||
|
sortFn: new Function("return " + (dataFns.sortFn || "undefined"))(),
|
||||||
|
filterFn: new Function("return " + (dataFns.filterFn || "undefined"))(),
|
||||||
|
mapFn: new Function("return " + (dataFns.mapFn || "undefined"))(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get folder state from local storage
|
||||||
|
const storageTree = localStorage.getItem("fileTree")
|
||||||
|
const serializedExplorerState = storageTree && opts.useSavedState ? JSON.parse(storageTree) : []
|
||||||
|
const oldIndex = new Map<string, boolean>(
|
||||||
|
serializedExplorerState.map((entry: FolderState) => [entry.path, entry.collapsed]),
|
||||||
|
)
|
||||||
|
|
||||||
|
const data = await fetchData
|
||||||
|
const entries = [...Object.entries(data)] as [FullSlug, ContentDetails][]
|
||||||
|
const trie = FileTrieNode.fromEntries(entries)
|
||||||
|
|
||||||
|
// Apply functions in order
|
||||||
|
for (const fn of opts.order) {
|
||||||
|
switch (fn) {
|
||||||
|
case "filter":
|
||||||
|
if (opts.filterFn) trie.filter(opts.filterFn)
|
||||||
|
break
|
||||||
|
case "map":
|
||||||
|
if (opts.mapFn) trie.map(opts.mapFn)
|
||||||
|
break
|
||||||
|
case "sort":
|
||||||
|
if (opts.sortFn) trie.sort(opts.sortFn)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get folder paths for state management
|
||||||
|
const folderPaths = trie.getFolderPaths()
|
||||||
|
currentExplorerState = folderPaths.map((path) => {
|
||||||
|
const previousState = oldIndex.get(path)
|
||||||
|
return {
|
||||||
|
path,
|
||||||
|
collapsed:
|
||||||
|
previousState === undefined ? opts.folderDefaultState === "collapsed" : previousState,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const explorerUl = explorer.querySelector(".explorer-ul")
|
||||||
|
if (!explorerUl) continue
|
||||||
|
|
||||||
|
// Create and insert new content
|
||||||
|
const fragment = document.createDocumentFragment()
|
||||||
|
for (const child of trie.children) {
|
||||||
|
const node = child.isFolder
|
||||||
|
? createFolderNode(currentSlug, child, opts)
|
||||||
|
: createFileNode(currentSlug, child)
|
||||||
|
|
||||||
|
fragment.appendChild(node)
|
||||||
|
}
|
||||||
|
explorerUl.insertBefore(fragment, explorerUl.firstChild)
|
||||||
|
|
||||||
|
// restore explorer scrollTop position if it exists
|
||||||
|
const scrollTop = sessionStorage.getItem("explorerScrollTop")
|
||||||
|
if (scrollTop) {
|
||||||
|
explorerUl.scrollTop = parseInt(scrollTop)
|
||||||
|
} else {
|
||||||
|
// try to scroll to the active element if it exists
|
||||||
|
const activeElement = explorerUl.querySelector(".active")
|
||||||
|
if (activeElement) {
|
||||||
|
activeElement.scrollIntoView({ behavior: "smooth" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up event handlers
|
||||||
|
const explorerButtons = explorer.getElementsByClassName(
|
||||||
|
"explorer-toggle",
|
||||||
|
) as HTMLCollectionOf<HTMLElement>
|
||||||
|
for (const button of explorerButtons) {
|
||||||
|
button.addEventListener("click", toggleExplorer)
|
||||||
|
window.addCleanup(() => button.removeEventListener("click", toggleExplorer))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up folder click handlers
|
||||||
|
if (opts.folderClickBehavior === "collapse") {
|
||||||
|
const folderButtons = explorer.getElementsByClassName(
|
||||||
|
"folder-button",
|
||||||
|
) as HTMLCollectionOf<HTMLElement>
|
||||||
|
for (const button of folderButtons) {
|
||||||
|
button.addEventListener("click", toggleFolder)
|
||||||
|
window.addCleanup(() => button.removeEventListener("click", toggleFolder))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const folderIcons = explorer.getElementsByClassName(
|
||||||
|
"folder-icon",
|
||||||
|
) as HTMLCollectionOf<HTMLElement>
|
||||||
|
for (const icon of folderIcons) {
|
||||||
|
icon.addEventListener("click", toggleFolder)
|
||||||
|
window.addCleanup(() => icon.removeEventListener("click", toggleFolder))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("prenav", async () => {
|
||||||
|
// save explorer scrollTop position
|
||||||
|
const explorer = document.querySelector(".explorer-ul")
|
||||||
|
if (!explorer) return
|
||||||
|
sessionStorage.setItem("explorerScrollTop", explorer.scrollTop.toString())
|
||||||
|
})
|
||||||
|
|
||||||
|
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||||
|
const currentSlug = e.detail.url
|
||||||
|
await setupExplorer(currentSlug)
|
||||||
|
|
||||||
|
// if mobile hamburger is visible, collapse by default
|
||||||
|
for (const explorer of document.getElementsByClassName("explorer")) {
|
||||||
|
const mobileExplorer = explorer.querySelector(".mobile-explorer")
|
||||||
|
if (!mobileExplorer) return
|
||||||
|
|
||||||
|
if (mobileExplorer.checkVisibility()) {
|
||||||
|
explorer.classList.add("collapsed")
|
||||||
|
explorer.setAttribute("aria-expanded", "false")
|
||||||
|
|
||||||
|
// Allow <html> to be scrollable when mobile explorer is collapsed
|
||||||
|
document.documentElement.classList.remove("mobile-no-scroll")
|
||||||
|
}
|
||||||
|
|
||||||
|
mobileExplorer.classList.remove("hide-until-loaded")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
window.addEventListener("resize", function () {
|
||||||
|
// Desktop explorer opens by default, and it stays open when the window is resized
|
||||||
|
// to mobile screen size. Applies `no-scroll` to <html> in this edge case.
|
||||||
|
const explorer = document.querySelector(".explorer")
|
||||||
|
if (explorer && !explorer.classList.contains("collapsed")) {
|
||||||
|
document.documentElement.classList.add("mobile-no-scroll")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles the state of a given folder
|
|
||||||
* @param folderElement <div class="folder-outer"> Element of folder (parent)
|
|
||||||
* @param collapsed if folder should be set to collapsed or not
|
|
||||||
*/
|
|
||||||
function setFolderState(folderElement: HTMLElement, collapsed: boolean) {
|
function setFolderState(folderElement: HTMLElement, collapsed: boolean) {
|
||||||
return collapsed ? folderElement.classList.remove("open") : folderElement.classList.add("open")
|
return collapsed ? folderElement.classList.remove("open") : folderElement.classList.add("open")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles visibility of a folder
|
|
||||||
* @param array array of FolderState (`fileTree`, either get from local storage or data attribute)
|
|
||||||
* @param path path to folder (e.g. 'advanced/more/more2')
|
|
||||||
*/
|
|
||||||
function toggleCollapsedByPath(array: FolderState[], path: string) {
|
|
||||||
const entry = array.find((item) => item.path === path)
|
|
||||||
if (entry) {
|
|
||||||
entry.collapsed = !entry.collapsed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
forceCenter,
|
forceCenter,
|
||||||
forceLink,
|
forceLink,
|
||||||
forceCollide,
|
forceCollide,
|
||||||
|
forceRadial,
|
||||||
zoomIdentity,
|
zoomIdentity,
|
||||||
select,
|
select,
|
||||||
drag,
|
drag,
|
||||||
@ -67,11 +68,33 @@ type TweenNode = {
|
|||||||
stop: () => void
|
stop: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderGraph(container: string, fullSlug: FullSlug) {
|
// workaround for pixijs webgpu issue: https://github.com/pixijs/pixijs/issues/11389
|
||||||
|
async function determineGraphicsAPI(): Promise<"webgpu" | "webgl"> {
|
||||||
|
const adapter = await navigator.gpu?.requestAdapter().catch(() => null)
|
||||||
|
const device = adapter && (await adapter.requestDevice().catch(() => null))
|
||||||
|
if (!device) {
|
||||||
|
return "webgl"
|
||||||
|
}
|
||||||
|
|
||||||
|
const canvas = document.createElement("canvas")
|
||||||
|
const gl =
|
||||||
|
(canvas.getContext("webgl2") as WebGL2RenderingContext | null) ??
|
||||||
|
(canvas.getContext("webgl") as WebGLRenderingContext | null)
|
||||||
|
|
||||||
|
// we have to return webgl so pixijs automatically falls back to canvas
|
||||||
|
if (!gl) {
|
||||||
|
return "webgl"
|
||||||
|
}
|
||||||
|
|
||||||
|
const webglMaxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS)
|
||||||
|
const webgpuMaxTextures = device.limits.maxSampledTexturesPerShaderStage
|
||||||
|
|
||||||
|
return webglMaxTextures === webgpuMaxTextures ? "webgpu" : "webgl"
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderGraph(graph: HTMLElement, fullSlug: FullSlug) {
|
||||||
const slug = simplifySlug(fullSlug)
|
const slug = simplifySlug(fullSlug)
|
||||||
const visited = getVisited()
|
const visited = getVisited()
|
||||||
const graph = document.getElementById(container)
|
|
||||||
if (!graph) return
|
|
||||||
removeAllChildren(graph)
|
removeAllChildren(graph)
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@ -87,6 +110,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
removeTags,
|
removeTags,
|
||||||
showTags,
|
showTags,
|
||||||
focusOnHover,
|
focusOnHover,
|
||||||
|
enableRadial,
|
||||||
} = JSON.parse(graph.dataset["cfg"]!) as D3Config
|
} = JSON.parse(graph.dataset["cfg"]!) as D3Config
|
||||||
|
|
||||||
const data: Map<SimpleSlug, ContentDetails> = new Map(
|
const data: Map<SimpleSlug, ContentDetails> = new Map(
|
||||||
@ -161,6 +185,9 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const width = graph.offsetWidth
|
||||||
|
const height = Math.max(graph.offsetHeight, 250)
|
||||||
|
|
||||||
// we virtualize the simulation and use pixi to actually render it
|
// we virtualize the simulation and use pixi to actually render it
|
||||||
const simulation: Simulation<NodeData, LinkData> = forceSimulation<NodeData>(graphData.nodes)
|
const simulation: Simulation<NodeData, LinkData> = forceSimulation<NodeData>(graphData.nodes)
|
||||||
.force("charge", forceManyBody().strength(-100 * repelForce))
|
.force("charge", forceManyBody().strength(-100 * repelForce))
|
||||||
@ -168,8 +195,8 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
.force("link", forceLink(graphData.links).distance(linkDistance))
|
.force("link", forceLink(graphData.links).distance(linkDistance))
|
||||||
.force("collide", forceCollide<NodeData>((n) => nodeRadius(n)).iterations(3))
|
.force("collide", forceCollide<NodeData>((n) => nodeRadius(n)).iterations(3))
|
||||||
|
|
||||||
const width = graph.offsetWidth
|
const radius = (Math.min(width, height) / 2) * 0.8
|
||||||
const height = Math.max(graph.offsetHeight, 250)
|
if (enableRadial) simulation.force("radial", forceRadial(radius).strength(0.2))
|
||||||
|
|
||||||
// precompute style prop strings as pixi doesn't support css variables
|
// precompute style prop strings as pixi doesn't support css variables
|
||||||
const cssVars = [
|
const cssVars = [
|
||||||
@ -346,6 +373,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
tweens.forEach((tween) => tween.stop())
|
tweens.forEach((tween) => tween.stop())
|
||||||
tweens.clear()
|
tweens.clear()
|
||||||
|
|
||||||
|
const pixiPreference = await determineGraphicsAPI()
|
||||||
const app = new Application()
|
const app = new Application()
|
||||||
await app.init({
|
await app.init({
|
||||||
width,
|
width,
|
||||||
@ -354,7 +382,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
autoStart: false,
|
autoStart: false,
|
||||||
autoDensity: true,
|
autoDensity: true,
|
||||||
backgroundAlpha: 0,
|
backgroundAlpha: 0,
|
||||||
preference: "webgpu",
|
preference: pixiPreference,
|
||||||
resolution: window.devicePixelRatio,
|
resolution: window.devicePixelRatio,
|
||||||
eventMode: "static",
|
eventMode: "static",
|
||||||
})
|
})
|
||||||
@ -363,9 +391,9 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
const stage = app.stage
|
const stage = app.stage
|
||||||
stage.interactive = false
|
stage.interactive = false
|
||||||
|
|
||||||
const labelsContainer = new Container<Text>({ zIndex: 3 })
|
const labelsContainer = new Container<Text>({ zIndex: 3, isRenderGroup: true })
|
||||||
const nodesContainer = new Container<Graphics>({ zIndex: 2 })
|
const nodesContainer = new Container<Graphics>({ zIndex: 2, isRenderGroup: true })
|
||||||
const linkContainer = new Container<Graphics>({ zIndex: 1 })
|
const linkContainer = new Container<Graphics>({ zIndex: 1, isRenderGroup: true })
|
||||||
stage.addChild(nodesContainer, labelsContainer, linkContainer)
|
stage.addChild(nodesContainer, labelsContainer, linkContainer)
|
||||||
|
|
||||||
for (const n of graphData.nodes) {
|
for (const n of graphData.nodes) {
|
||||||
@ -397,7 +425,6 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
})
|
})
|
||||||
.circle(0, 0, nodeRadius(n))
|
.circle(0, 0, nodeRadius(n))
|
||||||
.fill({ color: isTagNode ? computedStyleMap["--light"] : color(n) })
|
.fill({ color: isTagNode ? computedStyleMap["--light"] : color(n) })
|
||||||
.stroke({ width: isTagNode ? 2 : 0, color: color(n) })
|
|
||||||
.on("pointerover", (e) => {
|
.on("pointerover", (e) => {
|
||||||
updateHoverInfo(e.target.label)
|
updateHoverInfo(e.target.label)
|
||||||
oldLabelOpacity = label.alpha
|
oldLabelOpacity = label.alpha
|
||||||
@ -413,6 +440,10 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (isTagNode) {
|
||||||
|
gfx.stroke({ width: 2, color: computedStyleMap["--tertiary"] })
|
||||||
|
}
|
||||||
|
|
||||||
nodesContainer.addChild(gfx)
|
nodesContainer.addChild(gfx)
|
||||||
labelsContainer.addChild(label)
|
labelsContainer.addChild(label)
|
||||||
|
|
||||||
@ -517,7 +548,9 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let stopAnimation = false
|
||||||
function animate(time: number) {
|
function animate(time: number) {
|
||||||
|
if (stopAnimation) return
|
||||||
for (const n of nodeRenderData) {
|
for (const n of nodeRenderData) {
|
||||||
const { x, y } = n.simulationData
|
const { x, y } = n.simulationData
|
||||||
if (!x || !y) continue
|
if (!x || !y) continue
|
||||||
@ -541,48 +574,101 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
requestAnimationFrame(animate)
|
requestAnimationFrame(animate)
|
||||||
}
|
}
|
||||||
|
|
||||||
const graphAnimationFrameHandle = requestAnimationFrame(animate)
|
requestAnimationFrame(animate)
|
||||||
window.addCleanup(() => cancelAnimationFrame(graphAnimationFrameHandle))
|
return () => {
|
||||||
|
stopAnimation = true
|
||||||
|
app.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let localGraphCleanups: (() => void)[] = []
|
||||||
|
let globalGraphCleanups: (() => void)[] = []
|
||||||
|
|
||||||
|
function cleanupLocalGraphs() {
|
||||||
|
for (const cleanup of localGraphCleanups) {
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
localGraphCleanups = []
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanupGlobalGraphs() {
|
||||||
|
for (const cleanup of globalGraphCleanups) {
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
globalGraphCleanups = []
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||||
const slug = e.detail.url
|
const slug = e.detail.url
|
||||||
addToVisited(simplifySlug(slug))
|
addToVisited(simplifySlug(slug))
|
||||||
await renderGraph("graph-container", slug)
|
|
||||||
|
|
||||||
const container = document.getElementById("global-graph-outer")
|
async function renderLocalGraph() {
|
||||||
const sidebar = container?.closest(".sidebar") as HTMLElement
|
cleanupLocalGraphs()
|
||||||
|
const localGraphContainers = document.getElementsByClassName("graph-container")
|
||||||
function renderGlobalGraph() {
|
for (const container of localGraphContainers) {
|
||||||
const slug = getFullSlug(window)
|
localGraphCleanups.push(await renderGraph(container as HTMLElement, slug))
|
||||||
container?.classList.add("active")
|
|
||||||
if (sidebar) {
|
|
||||||
sidebar.style.zIndex = "1"
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderGraph("global-graph-container", slug)
|
await renderLocalGraph()
|
||||||
registerEscapeHandler(container, hideGlobalGraph)
|
const handleThemeChange = () => {
|
||||||
|
void renderLocalGraph()
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("themechange", handleThemeChange)
|
||||||
|
window.addCleanup(() => {
|
||||||
|
document.removeEventListener("themechange", handleThemeChange)
|
||||||
|
})
|
||||||
|
|
||||||
|
const containers = [...document.getElementsByClassName("global-graph-outer")] as HTMLElement[]
|
||||||
|
async function renderGlobalGraph() {
|
||||||
|
const slug = getFullSlug(window)
|
||||||
|
for (const container of containers) {
|
||||||
|
container.classList.add("active")
|
||||||
|
const sidebar = container.closest(".sidebar") as HTMLElement
|
||||||
|
if (sidebar) {
|
||||||
|
sidebar.style.zIndex = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
const graphContainer = container.querySelector(".global-graph-container") as HTMLElement
|
||||||
|
registerEscapeHandler(container, hideGlobalGraph)
|
||||||
|
if (graphContainer) {
|
||||||
|
globalGraphCleanups.push(await renderGraph(graphContainer, slug))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideGlobalGraph() {
|
function hideGlobalGraph() {
|
||||||
container?.classList.remove("active")
|
cleanupGlobalGraphs()
|
||||||
if (sidebar) {
|
for (const container of containers) {
|
||||||
sidebar.style.zIndex = "unset"
|
container.classList.remove("active")
|
||||||
|
const sidebar = container.closest(".sidebar") as HTMLElement
|
||||||
|
if (sidebar) {
|
||||||
|
sidebar.style.zIndex = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shortcutHandler(e: HTMLElementEventMap["keydown"]) {
|
async function shortcutHandler(e: HTMLElementEventMap["keydown"]) {
|
||||||
if (e.key === "g" && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
if (e.key === "g" && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const globalGraphOpen = container?.classList.contains("active")
|
const anyGlobalGraphOpen = containers.some((container) =>
|
||||||
globalGraphOpen ? hideGlobalGraph() : renderGlobalGraph()
|
container.classList.contains("active"),
|
||||||
|
)
|
||||||
|
anyGlobalGraphOpen ? hideGlobalGraph() : renderGlobalGraph()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const containerIcon = document.getElementById("global-graph-icon")
|
const containerIcons = document.getElementsByClassName("global-graph-icon")
|
||||||
containerIcon?.addEventListener("click", renderGlobalGraph)
|
Array.from(containerIcons).forEach((icon) => {
|
||||||
window.addCleanup(() => containerIcon?.removeEventListener("click", renderGlobalGraph))
|
icon.addEventListener("click", renderGlobalGraph)
|
||||||
|
window.addCleanup(() => icon.removeEventListener("click", renderGlobalGraph))
|
||||||
|
})
|
||||||
|
|
||||||
document.addEventListener("keydown", shortcutHandler)
|
document.addEventListener("keydown", shortcutHandler)
|
||||||
window.addCleanup(() => document.removeEventListener("keydown", shortcutHandler))
|
window.addCleanup(() => {
|
||||||
|
document.removeEventListener("keydown", shortcutHandler)
|
||||||
|
cleanupLocalGraphs()
|
||||||
|
cleanupGlobalGraphs()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
258
quartz/components/scripts/mermaid.inline.ts
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
import { registerEscapeHandler, removeAllChildren } from "./util"
|
||||||
|
|
||||||
|
interface Position {
|
||||||
|
x: number
|
||||||
|
y: number
|
||||||
|
}
|
||||||
|
|
||||||
|
class DiagramPanZoom {
|
||||||
|
private isDragging = false
|
||||||
|
private startPan: Position = { x: 0, y: 0 }
|
||||||
|
private currentPan: Position = { x: 0, y: 0 }
|
||||||
|
private scale = 1
|
||||||
|
private readonly MIN_SCALE = 0.5
|
||||||
|
private readonly MAX_SCALE = 3
|
||||||
|
|
||||||
|
cleanups: (() => void)[] = []
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private container: HTMLElement,
|
||||||
|
private content: HTMLElement,
|
||||||
|
) {
|
||||||
|
this.setupEventListeners()
|
||||||
|
this.setupNavigationControls()
|
||||||
|
this.resetTransform()
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupEventListeners() {
|
||||||
|
// Mouse drag events
|
||||||
|
const mouseDownHandler = this.onMouseDown.bind(this)
|
||||||
|
const mouseMoveHandler = this.onMouseMove.bind(this)
|
||||||
|
const mouseUpHandler = this.onMouseUp.bind(this)
|
||||||
|
const resizeHandler = this.resetTransform.bind(this)
|
||||||
|
|
||||||
|
this.container.addEventListener("mousedown", mouseDownHandler)
|
||||||
|
document.addEventListener("mousemove", mouseMoveHandler)
|
||||||
|
document.addEventListener("mouseup", mouseUpHandler)
|
||||||
|
window.addEventListener("resize", resizeHandler)
|
||||||
|
|
||||||
|
this.cleanups.push(
|
||||||
|
() => this.container.removeEventListener("mousedown", mouseDownHandler),
|
||||||
|
() => document.removeEventListener("mousemove", mouseMoveHandler),
|
||||||
|
() => document.removeEventListener("mouseup", mouseUpHandler),
|
||||||
|
() => window.removeEventListener("resize", resizeHandler),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
for (const cleanup of this.cleanups) {
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupNavigationControls() {
|
||||||
|
const controls = document.createElement("div")
|
||||||
|
controls.className = "mermaid-controls"
|
||||||
|
|
||||||
|
// Zoom controls
|
||||||
|
const zoomIn = this.createButton("+", () => this.zoom(0.1))
|
||||||
|
const zoomOut = this.createButton("-", () => this.zoom(-0.1))
|
||||||
|
const resetBtn = this.createButton("Reset", () => this.resetTransform())
|
||||||
|
|
||||||
|
controls.appendChild(zoomOut)
|
||||||
|
controls.appendChild(resetBtn)
|
||||||
|
controls.appendChild(zoomIn)
|
||||||
|
|
||||||
|
this.container.appendChild(controls)
|
||||||
|
}
|
||||||
|
|
||||||
|
private createButton(text: string, onClick: () => void): HTMLButtonElement {
|
||||||
|
const button = document.createElement("button")
|
||||||
|
button.textContent = text
|
||||||
|
button.className = "mermaid-control-button"
|
||||||
|
button.addEventListener("click", onClick)
|
||||||
|
window.addCleanup(() => button.removeEventListener("click", onClick))
|
||||||
|
return button
|
||||||
|
}
|
||||||
|
|
||||||
|
private onMouseDown(e: MouseEvent) {
|
||||||
|
if (e.button !== 0) return // Only handle left click
|
||||||
|
this.isDragging = true
|
||||||
|
this.startPan = { x: e.clientX - this.currentPan.x, y: e.clientY - this.currentPan.y }
|
||||||
|
this.container.style.cursor = "grabbing"
|
||||||
|
}
|
||||||
|
|
||||||
|
private onMouseMove(e: MouseEvent) {
|
||||||
|
if (!this.isDragging) return
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
this.currentPan = {
|
||||||
|
x: e.clientX - this.startPan.x,
|
||||||
|
y: e.clientY - this.startPan.y,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateTransform()
|
||||||
|
}
|
||||||
|
|
||||||
|
private onMouseUp() {
|
||||||
|
this.isDragging = false
|
||||||
|
this.container.style.cursor = "grab"
|
||||||
|
}
|
||||||
|
|
||||||
|
private zoom(delta: number) {
|
||||||
|
const newScale = Math.min(Math.max(this.scale + delta, this.MIN_SCALE), this.MAX_SCALE)
|
||||||
|
|
||||||
|
// Zoom around center
|
||||||
|
const rect = this.content.getBoundingClientRect()
|
||||||
|
const centerX = rect.width / 2
|
||||||
|
const centerY = rect.height / 2
|
||||||
|
|
||||||
|
const scaleDiff = newScale - this.scale
|
||||||
|
this.currentPan.x -= centerX * scaleDiff
|
||||||
|
this.currentPan.y -= centerY * scaleDiff
|
||||||
|
|
||||||
|
this.scale = newScale
|
||||||
|
this.updateTransform()
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateTransform() {
|
||||||
|
this.content.style.transform = `translate(${this.currentPan.x}px, ${this.currentPan.y}px) scale(${this.scale})`
|
||||||
|
}
|
||||||
|
|
||||||
|
private resetTransform() {
|
||||||
|
this.scale = 1
|
||||||
|
const svg = this.content.querySelector("svg")!
|
||||||
|
this.currentPan = {
|
||||||
|
x: svg.getBoundingClientRect().width / 2,
|
||||||
|
y: svg.getBoundingClientRect().height / 2,
|
||||||
|
}
|
||||||
|
this.updateTransform()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cssVars = [
|
||||||
|
"--secondary",
|
||||||
|
"--tertiary",
|
||||||
|
"--gray",
|
||||||
|
"--light",
|
||||||
|
"--lightgray",
|
||||||
|
"--highlight",
|
||||||
|
"--dark",
|
||||||
|
"--darkgray",
|
||||||
|
"--codeFont",
|
||||||
|
] as const
|
||||||
|
|
||||||
|
let mermaidImport = undefined
|
||||||
|
document.addEventListener("nav", async () => {
|
||||||
|
const center = document.querySelector(".center") as HTMLElement
|
||||||
|
const nodes = center.querySelectorAll("code.mermaid") as NodeListOf<HTMLElement>
|
||||||
|
if (nodes.length === 0) return
|
||||||
|
|
||||||
|
mermaidImport ||= await import(
|
||||||
|
// @ts-ignore
|
||||||
|
"https://cdnjs.cloudflare.com/ajax/libs/mermaid/11.4.0/mermaid.esm.min.mjs"
|
||||||
|
)
|
||||||
|
const mermaid = mermaidImport.default
|
||||||
|
|
||||||
|
const textMapping: WeakMap<HTMLElement, string> = new WeakMap()
|
||||||
|
for (const node of nodes) {
|
||||||
|
textMapping.set(node, node.innerText)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderMermaid() {
|
||||||
|
// de-init any other diagrams
|
||||||
|
for (const node of nodes) {
|
||||||
|
node.removeAttribute("data-processed")
|
||||||
|
const oldText = textMapping.get(node)
|
||||||
|
if (oldText) {
|
||||||
|
node.innerHTML = oldText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const computedStyleMap = cssVars.reduce(
|
||||||
|
(acc, key) => {
|
||||||
|
acc[key] = window.getComputedStyle(document.documentElement).getPropertyValue(key)
|
||||||
|
return acc
|
||||||
|
},
|
||||||
|
{} as Record<(typeof cssVars)[number], string>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const darkMode = document.documentElement.getAttribute("saved-theme") === "dark"
|
||||||
|
mermaid.initialize({
|
||||||
|
startOnLoad: false,
|
||||||
|
securityLevel: "loose",
|
||||||
|
theme: darkMode ? "dark" : "base",
|
||||||
|
themeVariables: {
|
||||||
|
fontFamily: computedStyleMap["--codeFont"],
|
||||||
|
primaryColor: computedStyleMap["--light"],
|
||||||
|
primaryTextColor: computedStyleMap["--darkgray"],
|
||||||
|
primaryBorderColor: computedStyleMap["--tertiary"],
|
||||||
|
lineColor: computedStyleMap["--darkgray"],
|
||||||
|
secondaryColor: computedStyleMap["--secondary"],
|
||||||
|
tertiaryColor: computedStyleMap["--tertiary"],
|
||||||
|
clusterBkg: computedStyleMap["--light"],
|
||||||
|
edgeLabelBackground: computedStyleMap["--highlight"],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await mermaid.run({ nodes })
|
||||||
|
}
|
||||||
|
|
||||||
|
await renderMermaid()
|
||||||
|
document.addEventListener("themechange", renderMermaid)
|
||||||
|
window.addCleanup(() => document.removeEventListener("themechange", renderMermaid))
|
||||||
|
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
const codeBlock = nodes[i] as HTMLElement
|
||||||
|
const pre = codeBlock.parentElement as HTMLPreElement
|
||||||
|
const clipboardBtn = pre.querySelector(".clipboard-button") as HTMLButtonElement
|
||||||
|
const expandBtn = pre.querySelector(".expand-button") as HTMLButtonElement
|
||||||
|
|
||||||
|
const clipboardStyle = window.getComputedStyle(clipboardBtn)
|
||||||
|
const clipboardWidth =
|
||||||
|
clipboardBtn.offsetWidth +
|
||||||
|
parseFloat(clipboardStyle.marginLeft || "0") +
|
||||||
|
parseFloat(clipboardStyle.marginRight || "0")
|
||||||
|
|
||||||
|
// Set expand button position
|
||||||
|
expandBtn.style.right = `calc(${clipboardWidth}px + 0.3rem)`
|
||||||
|
pre.prepend(expandBtn)
|
||||||
|
|
||||||
|
// query popup container
|
||||||
|
const popupContainer = pre.querySelector("#mermaid-container") as HTMLElement
|
||||||
|
if (!popupContainer) return
|
||||||
|
|
||||||
|
let panZoom: DiagramPanZoom | null = null
|
||||||
|
function showMermaid() {
|
||||||
|
const container = popupContainer.querySelector("#mermaid-space") as HTMLElement
|
||||||
|
const content = popupContainer.querySelector(".mermaid-content") as HTMLElement
|
||||||
|
if (!content) return
|
||||||
|
removeAllChildren(content)
|
||||||
|
|
||||||
|
// Clone the mermaid content
|
||||||
|
const mermaidContent = codeBlock.querySelector("svg")!.cloneNode(true) as SVGElement
|
||||||
|
content.appendChild(mermaidContent)
|
||||||
|
|
||||||
|
// Show container
|
||||||
|
popupContainer.classList.add("active")
|
||||||
|
container.style.cursor = "grab"
|
||||||
|
|
||||||
|
// Initialize pan-zoom after showing the popup
|
||||||
|
panZoom = new DiagramPanZoom(container, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideMermaid() {
|
||||||
|
popupContainer.classList.remove("active")
|
||||||
|
panZoom?.cleanup()
|
||||||
|
panZoom = null
|
||||||
|
}
|
||||||
|
|
||||||
|
expandBtn.addEventListener("click", showMermaid)
|
||||||
|
registerEscapeHandler(popupContainer, hideMermaid)
|
||||||
|
|
||||||
|
window.addCleanup(() => {
|
||||||
|
panZoom?.cleanup()
|
||||||
|
expandBtn.removeEventListener("click", showMermaid)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
@ -1,62 +1,72 @@
|
|||||||
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
||||||
import { normalizeRelativeURLs } from "../../util/path"
|
import { normalizeRelativeURLs } from "../../util/path"
|
||||||
|
import { fetchCanonical } from "./util"
|
||||||
|
|
||||||
const p = new DOMParser()
|
const p = new DOMParser()
|
||||||
|
let activeAnchor: HTMLAnchorElement | null = null
|
||||||
|
|
||||||
async function mouseEnterHandler(
|
async function mouseEnterHandler(
|
||||||
this: HTMLAnchorElement,
|
this: HTMLAnchorElement,
|
||||||
{ clientX, clientY }: { clientX: number; clientY: number },
|
{ clientX, clientY }: { clientX: number; clientY: number },
|
||||||
) {
|
) {
|
||||||
const link = this
|
const link = (activeAnchor = this)
|
||||||
if (link.dataset.noPopover === "true") {
|
if (link.dataset.noPopover === "true") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setPosition(popoverElement: HTMLElement) {
|
async function setPosition(popoverElement: HTMLElement) {
|
||||||
const { x, y } = await computePosition(link, popoverElement, {
|
const { x, y } = await computePosition(link, popoverElement, {
|
||||||
|
strategy: "fixed",
|
||||||
middleware: [inline({ x: clientX, y: clientY }), shift(), flip()],
|
middleware: [inline({ x: clientX, y: clientY }), shift(), flip()],
|
||||||
})
|
})
|
||||||
Object.assign(popoverElement.style, {
|
Object.assign(popoverElement.style, {
|
||||||
left: `${x}px`,
|
transform: `translate(${x.toFixed()}px, ${y.toFixed()}px)`,
|
||||||
top: `${y}px`,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasAlreadyBeenFetched = () =>
|
function showPopover(popoverElement: HTMLElement) {
|
||||||
[...link.children].some((child) => child.classList.contains("popover"))
|
clearActivePopover()
|
||||||
|
popoverElement.classList.add("active-popover")
|
||||||
|
setPosition(popoverElement as HTMLElement)
|
||||||
|
|
||||||
// dont refetch if there's already a popover
|
if (hash !== "") {
|
||||||
if (hasAlreadyBeenFetched()) {
|
const targetAnchor = `#popover-internal-${hash.slice(1)}`
|
||||||
return setPosition(link.lastChild as HTMLElement)
|
const heading = popoverInner.querySelector(targetAnchor) as HTMLElement | null
|
||||||
|
if (heading) {
|
||||||
|
// leave ~12px of buffer when scrolling to a heading
|
||||||
|
popoverInner.scroll({ top: heading.offsetTop - 12, behavior: "instant" })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const thisUrl = new URL(document.location.href)
|
|
||||||
thisUrl.hash = ""
|
|
||||||
thisUrl.search = ""
|
|
||||||
const targetUrl = new URL(link.href)
|
const targetUrl = new URL(link.href)
|
||||||
const hash = decodeURIComponent(targetUrl.hash)
|
const hash = decodeURIComponent(targetUrl.hash)
|
||||||
targetUrl.hash = ""
|
targetUrl.hash = ""
|
||||||
targetUrl.search = ""
|
targetUrl.search = ""
|
||||||
|
const popoverId = `popover-${link.pathname}`
|
||||||
|
const prevPopoverElement = document.getElementById(popoverId)
|
||||||
|
|
||||||
const response = await fetch(`${targetUrl}`).catch((err) => {
|
// dont refetch if there's already a popover
|
||||||
console.error(err)
|
if (!!document.getElementById(popoverId)) {
|
||||||
})
|
showPopover(prevPopoverElement as HTMLElement)
|
||||||
|
|
||||||
// bailout if another popover exists
|
|
||||||
if (hasAlreadyBeenFetched()) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const response = await fetchCanonical(targetUrl).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
})
|
||||||
|
|
||||||
if (!response) return
|
if (!response) return
|
||||||
const [contentType] = response.headers.get("Content-Type")!.split(";")
|
const [contentType] = response.headers.get("Content-Type")!.split(";")
|
||||||
const [contentTypeCategory, typeInfo] = contentType.split("/")
|
const [contentTypeCategory, typeInfo] = contentType.split("/")
|
||||||
|
|
||||||
const popoverElement = document.createElement("div")
|
const popoverElement = document.createElement("div")
|
||||||
|
popoverElement.id = popoverId
|
||||||
popoverElement.classList.add("popover")
|
popoverElement.classList.add("popover")
|
||||||
const popoverInner = document.createElement("div")
|
const popoverInner = document.createElement("div")
|
||||||
popoverInner.classList.add("popover-inner")
|
popoverInner.classList.add("popover-inner")
|
||||||
popoverElement.appendChild(popoverInner)
|
|
||||||
|
|
||||||
popoverInner.dataset.contentType = contentType ?? undefined
|
popoverInner.dataset.contentType = contentType ?? undefined
|
||||||
|
popoverElement.appendChild(popoverInner)
|
||||||
|
|
||||||
switch (contentTypeCategory) {
|
switch (contentTypeCategory) {
|
||||||
case "image":
|
case "image":
|
||||||
@ -81,28 +91,43 @@ async function mouseEnterHandler(
|
|||||||
const contents = await response.text()
|
const contents = await response.text()
|
||||||
const html = p.parseFromString(contents, "text/html")
|
const html = p.parseFromString(contents, "text/html")
|
||||||
normalizeRelativeURLs(html, targetUrl)
|
normalizeRelativeURLs(html, targetUrl)
|
||||||
|
// prepend all IDs inside popovers to prevent duplicates
|
||||||
|
html.querySelectorAll("[id]").forEach((el) => {
|
||||||
|
const targetID = `popover-internal-${el.id}`
|
||||||
|
el.id = targetID
|
||||||
|
})
|
||||||
const elts = [...html.getElementsByClassName("popover-hint")]
|
const elts = [...html.getElementsByClassName("popover-hint")]
|
||||||
if (elts.length === 0) return
|
if (elts.length === 0) return
|
||||||
|
|
||||||
elts.forEach((elt) => popoverInner.appendChild(elt))
|
elts.forEach((elt) => popoverInner.appendChild(elt))
|
||||||
}
|
}
|
||||||
|
|
||||||
setPosition(popoverElement)
|
if (!!document.getElementById(popoverId)) {
|
||||||
link.appendChild(popoverElement)
|
return
|
||||||
|
|
||||||
if (hash !== "") {
|
|
||||||
const heading = popoverInner.querySelector(hash) as HTMLElement | null
|
|
||||||
if (heading) {
|
|
||||||
// leave ~12px of buffer when scrolling to a heading
|
|
||||||
popoverInner.scroll({ top: heading.offsetTop - 12, behavior: "instant" })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.body.appendChild(popoverElement)
|
||||||
|
if (activeAnchor !== this) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
showPopover(popoverElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearActivePopover() {
|
||||||
|
activeAnchor = null
|
||||||
|
const allPopoverElements = document.querySelectorAll(".popover")
|
||||||
|
allPopoverElements.forEach((popoverElement) => popoverElement.classList.remove("active-popover"))
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
const links = [...document.getElementsByClassName("internal")] as HTMLAnchorElement[]
|
const links = [...document.querySelectorAll("a.internal")] as HTMLAnchorElement[]
|
||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
link.addEventListener("mouseenter", mouseEnterHandler)
|
link.addEventListener("mouseenter", mouseEnterHandler)
|
||||||
window.addCleanup(() => link.removeEventListener("mouseenter", mouseEnterHandler))
|
link.addEventListener("mouseleave", clearActivePopover)
|
||||||
|
window.addCleanup(() => {
|
||||||
|
link.removeEventListener("mouseenter", mouseEnterHandler)
|
||||||
|
link.removeEventListener("mouseleave", clearActivePopover)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
25
quartz/components/scripts/readermode.inline.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
let isReaderMode = false
|
||||||
|
|
||||||
|
const emitReaderModeChangeEvent = (mode: "on" | "off") => {
|
||||||
|
const event: CustomEventMap["readermodechange"] = new CustomEvent("readermodechange", {
|
||||||
|
detail: { mode },
|
||||||
|
})
|
||||||
|
document.dispatchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("nav", () => {
|
||||||
|
const switchReaderMode = () => {
|
||||||
|
isReaderMode = !isReaderMode
|
||||||
|
const newMode = isReaderMode ? "on" : "off"
|
||||||
|
document.documentElement.setAttribute("reader-mode", newMode)
|
||||||
|
emitReaderModeChangeEvent(newMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const readerModeButton of document.getElementsByClassName("readermode")) {
|
||||||
|
readerModeButton.addEventListener("click", switchReaderMode)
|
||||||
|
window.addCleanup(() => readerModeButton.removeEventListener("click", switchReaderMode))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set initial state
|
||||||
|
document.documentElement.setAttribute("reader-mode", isReaderMode ? "on" : "off")
|
||||||
|
})
|
@ -143,83 +143,74 @@ function highlightHTML(searchTerm: string, el: HTMLElement) {
|
|||||||
return html.body
|
return html.body
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
async function setupSearch(searchElement: Element, currentSlug: FullSlug, data: ContentIndex) {
|
||||||
const currentSlug = e.detail.url
|
const container = searchElement.querySelector(".search-container") as HTMLElement
|
||||||
const data = await fetchData
|
if (!container) return
|
||||||
const container = document.getElementById("search-container")
|
|
||||||
const sidebar = container?.closest(".sidebar") as HTMLElement
|
|
||||||
const searchButton = document.getElementById("search-button")
|
|
||||||
const searchBar = document.getElementById("search-bar") as HTMLInputElement | null
|
|
||||||
const searchLayout = document.getElementById("search-layout")
|
|
||||||
const idDataMap = Object.keys(data) as FullSlug[]
|
|
||||||
|
|
||||||
|
const sidebar = container.closest(".sidebar") as HTMLElement | null
|
||||||
|
|
||||||
|
const searchButton = searchElement.querySelector(".search-button") as HTMLButtonElement
|
||||||
|
if (!searchButton) return
|
||||||
|
|
||||||
|
const searchBar = searchElement.querySelector(".search-bar") as HTMLInputElement
|
||||||
|
if (!searchBar) return
|
||||||
|
|
||||||
|
const searchLayout = searchElement.querySelector(".search-layout") as HTMLElement
|
||||||
|
if (!searchLayout) return
|
||||||
|
|
||||||
|
const idDataMap = Object.keys(data) as FullSlug[]
|
||||||
const appendLayout = (el: HTMLElement) => {
|
const appendLayout = (el: HTMLElement) => {
|
||||||
if (searchLayout?.querySelector(`#${el.id}`) === null) {
|
searchLayout.appendChild(el)
|
||||||
searchLayout?.appendChild(el)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const enablePreview = searchLayout?.dataset?.preview === "true"
|
const enablePreview = searchLayout.dataset.preview === "true"
|
||||||
let preview: HTMLDivElement | undefined = undefined
|
let preview: HTMLDivElement | undefined = undefined
|
||||||
let previewInner: HTMLDivElement | undefined = undefined
|
let previewInner: HTMLDivElement | undefined = undefined
|
||||||
const results = document.createElement("div")
|
const results = document.createElement("div")
|
||||||
results.id = "results-container"
|
results.className = "results-container"
|
||||||
appendLayout(results)
|
appendLayout(results)
|
||||||
|
|
||||||
if (enablePreview) {
|
if (enablePreview) {
|
||||||
preview = document.createElement("div")
|
preview = document.createElement("div")
|
||||||
preview.id = "preview-container"
|
preview.className = "preview-container"
|
||||||
appendLayout(preview)
|
appendLayout(preview)
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSearch() {
|
function hideSearch() {
|
||||||
container?.classList.remove("active")
|
container.classList.remove("active")
|
||||||
if (searchBar) {
|
searchBar.value = "" // clear the input when we dismiss the search
|
||||||
searchBar.value = "" // clear the input when we dismiss the search
|
if (sidebar) sidebar.style.zIndex = ""
|
||||||
}
|
removeAllChildren(results)
|
||||||
if (sidebar) {
|
|
||||||
sidebar.style.zIndex = "unset"
|
|
||||||
}
|
|
||||||
if (results) {
|
|
||||||
removeAllChildren(results)
|
|
||||||
}
|
|
||||||
if (preview) {
|
if (preview) {
|
||||||
removeAllChildren(preview)
|
removeAllChildren(preview)
|
||||||
}
|
}
|
||||||
if (searchLayout) {
|
searchLayout.classList.remove("display-results")
|
||||||
searchLayout.classList.remove("display-results")
|
|
||||||
}
|
|
||||||
|
|
||||||
searchType = "basic" // reset search type after closing
|
searchType = "basic" // reset search type after closing
|
||||||
|
searchButton.focus()
|
||||||
searchButton?.focus()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSearch(searchTypeNew: SearchType) {
|
function showSearch(searchTypeNew: SearchType) {
|
||||||
searchType = searchTypeNew
|
searchType = searchTypeNew
|
||||||
if (sidebar) {
|
if (sidebar) sidebar.style.zIndex = "1"
|
||||||
sidebar.style.zIndex = "1"
|
container.classList.add("active")
|
||||||
}
|
searchBar.focus()
|
||||||
container?.classList.add("active")
|
|
||||||
searchBar?.focus()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentHover: HTMLInputElement | null = null
|
let currentHover: HTMLInputElement | null = null
|
||||||
|
|
||||||
async function shortcutHandler(e: HTMLElementEventMap["keydown"]) {
|
async function shortcutHandler(e: HTMLElementEventMap["keydown"]) {
|
||||||
if (e.key === "k" && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
if (e.key === "k" && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const searchBarOpen = container?.classList.contains("active")
|
const searchBarOpen = container.classList.contains("active")
|
||||||
searchBarOpen ? hideSearch() : showSearch("basic")
|
searchBarOpen ? hideSearch() : showSearch("basic")
|
||||||
return
|
return
|
||||||
} else if (e.shiftKey && (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") {
|
} else if (e.shiftKey && (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") {
|
||||||
// Hotkey to open tag search
|
// Hotkey to open tag search
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const searchBarOpen = container?.classList.contains("active")
|
const searchBarOpen = container.classList.contains("active")
|
||||||
searchBarOpen ? hideSearch() : showSearch("tags")
|
searchBarOpen ? hideSearch() : showSearch("tags")
|
||||||
|
|
||||||
// add "#" prefix for tag search
|
// add "#" prefix for tag search
|
||||||
if (searchBar) searchBar.value = "#"
|
searchBar.value = "#"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,23 +219,23 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If search is active, then we will render the first result and display accordingly
|
// If search is active, then we will render the first result and display accordingly
|
||||||
if (!container?.classList.contains("active")) return
|
if (!container.classList.contains("active")) return
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
// If result has focus, navigate to that one, otherwise pick first result
|
// If result has focus, navigate to that one, otherwise pick first result
|
||||||
if (results?.contains(document.activeElement)) {
|
if (results.contains(document.activeElement)) {
|
||||||
const active = document.activeElement as HTMLInputElement
|
const active = document.activeElement as HTMLInputElement
|
||||||
if (active.classList.contains("no-match")) return
|
if (active.classList.contains("no-match")) return
|
||||||
await displayPreview(active)
|
await displayPreview(active)
|
||||||
active.click()
|
active.click()
|
||||||
} else {
|
} else {
|
||||||
const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null
|
const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null
|
||||||
if (!anchor || anchor?.classList.contains("no-match")) return
|
if (!anchor || anchor.classList.contains("no-match")) return
|
||||||
await displayPreview(anchor)
|
await displayPreview(anchor)
|
||||||
anchor.click()
|
anchor.click()
|
||||||
}
|
}
|
||||||
} else if (e.key === "ArrowUp" || (e.shiftKey && e.key === "Tab")) {
|
} else if (e.key === "ArrowUp" || (e.shiftKey && e.key === "Tab")) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (results?.contains(document.activeElement)) {
|
if (results.contains(document.activeElement)) {
|
||||||
// If an element in results-container already has focus, focus previous one
|
// If an element in results-container already has focus, focus previous one
|
||||||
const currentResult = currentHover
|
const currentResult = currentHover
|
||||||
? currentHover
|
? currentHover
|
||||||
@ -309,9 +300,11 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
|||||||
itemTile.classList.add("result-card")
|
itemTile.classList.add("result-card")
|
||||||
itemTile.id = slug
|
itemTile.id = slug
|
||||||
itemTile.href = resolveUrl(slug).toString()
|
itemTile.href = resolveUrl(slug).toString()
|
||||||
itemTile.innerHTML = `<h3>${title}</h3>${htmlTags}${
|
itemTile.innerHTML = `
|
||||||
enablePreview && window.innerWidth > 600 ? "" : `<p>${content}</p>`
|
<h3 class="card-title">${title}</h3>
|
||||||
}`
|
${htmlTags}
|
||||||
|
<p class="card-description">${content}</p>
|
||||||
|
`
|
||||||
itemTile.addEventListener("click", (event) => {
|
itemTile.addEventListener("click", (event) => {
|
||||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
||||||
hideSearch()
|
hideSearch()
|
||||||
@ -337,8 +330,6 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function displayResults(finalResults: Item[]) {
|
async function displayResults(finalResults: Item[]) {
|
||||||
if (!results) return
|
|
||||||
|
|
||||||
removeAllChildren(results)
|
removeAllChildren(results)
|
||||||
if (finalResults.length === 0) {
|
if (finalResults.length === 0) {
|
||||||
results.innerHTML = `<a class="result-card no-match">
|
results.innerHTML = `<a class="result-card no-match">
|
||||||
@ -394,7 +385,7 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
|||||||
preview.replaceChildren(previewInner)
|
preview.replaceChildren(previewInner)
|
||||||
|
|
||||||
// scroll to longest
|
// scroll to longest
|
||||||
const highlights = [...preview.querySelectorAll(".highlight")].sort(
|
const highlights = [...preview.getElementsByClassName("highlight")].sort(
|
||||||
(a, b) => b.innerHTML.length - a.innerHTML.length,
|
(a, b) => b.innerHTML.length - a.innerHTML.length,
|
||||||
)
|
)
|
||||||
highlights[0]?.scrollIntoView({ block: "start" })
|
highlights[0]?.scrollIntoView({ block: "start" })
|
||||||
@ -460,21 +451,23 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
|||||||
|
|
||||||
document.addEventListener("keydown", shortcutHandler)
|
document.addEventListener("keydown", shortcutHandler)
|
||||||
window.addCleanup(() => document.removeEventListener("keydown", shortcutHandler))
|
window.addCleanup(() => document.removeEventListener("keydown", shortcutHandler))
|
||||||
searchButton?.addEventListener("click", () => showSearch("basic"))
|
searchButton.addEventListener("click", () => showSearch("basic"))
|
||||||
window.addCleanup(() => searchButton?.removeEventListener("click", () => showSearch("basic")))
|
window.addCleanup(() => searchButton.removeEventListener("click", () => showSearch("basic")))
|
||||||
searchBar?.addEventListener("input", onType)
|
searchBar.addEventListener("input", onType)
|
||||||
window.addCleanup(() => searchBar?.removeEventListener("input", onType))
|
window.addCleanup(() => searchBar.removeEventListener("input", onType))
|
||||||
|
|
||||||
registerEscapeHandler(container, hideSearch)
|
registerEscapeHandler(container, hideSearch)
|
||||||
await fillDocument(data)
|
await fillDocument(data)
|
||||||
})
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills flexsearch document with data
|
* Fills flexsearch document with data
|
||||||
* @param index index to fill
|
* @param index index to fill
|
||||||
* @param data data to fill index with
|
* @param data data to fill index with
|
||||||
*/
|
*/
|
||||||
async function fillDocument(data: { [key: FullSlug]: ContentDetails }) {
|
let indexPopulated = false
|
||||||
|
async function fillDocument(data: ContentIndex) {
|
||||||
|
if (indexPopulated) return
|
||||||
let id = 0
|
let id = 0
|
||||||
const promises: Array<Promise<unknown>> = []
|
const promises: Array<Promise<unknown>> = []
|
||||||
for (const [slug, fileData] of Object.entries<ContentDetails>(data)) {
|
for (const [slug, fileData] of Object.entries<ContentDetails>(data)) {
|
||||||
@ -489,5 +482,15 @@ async function fillDocument(data: { [key: FullSlug]: ContentDetails }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
|
indexPopulated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||||
|
const currentSlug = e.detail.url
|
||||||
|
const data = await fetchData
|
||||||
|
const searchElement = document.getElementsByClassName("search")
|
||||||
|
for (const element of searchElement) {
|
||||||
|
await setupSearch(element, currentSlug, data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import micromorph from "micromorph"
|
import micromorph from "micromorph"
|
||||||
import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path"
|
import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path"
|
||||||
|
import { fetchCanonical } from "./util"
|
||||||
|
|
||||||
// adapted from `micromorph`
|
// adapted from `micromorph`
|
||||||
// https://github.com/natemoo-re/micromorph
|
// https://github.com/natemoo-re/micromorph
|
||||||
@ -42,10 +43,26 @@ function notifyNav(url: FullSlug) {
|
|||||||
const cleanupFns: Set<(...args: any[]) => void> = new Set()
|
const cleanupFns: Set<(...args: any[]) => void> = new Set()
|
||||||
window.addCleanup = (fn) => cleanupFns.add(fn)
|
window.addCleanup = (fn) => cleanupFns.add(fn)
|
||||||
|
|
||||||
|
function startLoading() {
|
||||||
|
const loadingBar = document.createElement("div")
|
||||||
|
loadingBar.className = "navigation-progress"
|
||||||
|
loadingBar.style.width = "0"
|
||||||
|
if (!document.body.contains(loadingBar)) {
|
||||||
|
document.body.appendChild(loadingBar)
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
loadingBar.style.width = "80%"
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
let isNavigating = false
|
||||||
let p: DOMParser
|
let p: DOMParser
|
||||||
async function navigate(url: URL, isBack: boolean = false) {
|
async function _navigate(url: URL, isBack: boolean = false) {
|
||||||
|
isNavigating = true
|
||||||
|
startLoading()
|
||||||
p = p || new DOMParser()
|
p = p || new DOMParser()
|
||||||
const contents = await fetch(`${url}`)
|
const contents = await fetchCanonical(url)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const contentType = res.headers.get("content-type")
|
const contentType = res.headers.get("content-type")
|
||||||
if (contentType?.startsWith("text/html")) {
|
if (contentType?.startsWith("text/html")) {
|
||||||
@ -60,6 +77,10 @@ async function navigate(url: URL, isBack: boolean = false) {
|
|||||||
|
|
||||||
if (!contents) return
|
if (!contents) return
|
||||||
|
|
||||||
|
// notify about to nav
|
||||||
|
const event: CustomEventMap["prenav"] = new CustomEvent("prenav", { detail: {} })
|
||||||
|
document.dispatchEvent(event)
|
||||||
|
|
||||||
// cleanup old
|
// cleanup old
|
||||||
cleanupFns.forEach((fn) => fn())
|
cleanupFns.forEach((fn) => fn())
|
||||||
cleanupFns.clear()
|
cleanupFns.clear()
|
||||||
@ -93,7 +114,7 @@ async function navigate(url: URL, isBack: boolean = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now, patch head
|
// now, patch head, re-executing scripts
|
||||||
const elementsToRemove = document.head.querySelectorAll(":not([spa-preserve])")
|
const elementsToRemove = document.head.querySelectorAll(":not([spa-preserve])")
|
||||||
elementsToRemove.forEach((el) => el.remove())
|
elementsToRemove.forEach((el) => el.remove())
|
||||||
const elementsToAdd = html.head.querySelectorAll(":not([spa-preserve])")
|
const elementsToAdd = html.head.querySelectorAll(":not([spa-preserve])")
|
||||||
@ -104,10 +125,24 @@ async function navigate(url: URL, isBack: boolean = false) {
|
|||||||
if (!isBack) {
|
if (!isBack) {
|
||||||
history.pushState({}, "", url)
|
history.pushState({}, "", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyNav(getFullSlug(window))
|
notifyNav(getFullSlug(window))
|
||||||
delete announcer.dataset.persist
|
delete announcer.dataset.persist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function navigate(url: URL, isBack: boolean = false) {
|
||||||
|
if (isNavigating) return
|
||||||
|
isNavigating = true
|
||||||
|
try {
|
||||||
|
await _navigate(url, isBack)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
window.location.assign(url)
|
||||||
|
} finally {
|
||||||
|
isNavigating = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.spaNavigate = navigate
|
window.spaNavigate = navigate
|
||||||
|
|
||||||
function createRouter() {
|
function createRouter() {
|
||||||
@ -125,21 +160,13 @@ function createRouter() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
navigate(url, false)
|
||||||
navigate(url, false)
|
|
||||||
} catch (e) {
|
|
||||||
window.location.assign(url)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
window.addEventListener("popstate", (event) => {
|
window.addEventListener("popstate", (event) => {
|
||||||
const { url } = getOpts(event) ?? {}
|
const { url } = getOpts(event) ?? {}
|
||||||
if (window.location.hash && window.location.pathname === url?.pathname) return
|
if (window.location.hash && window.location.pathname === url?.pathname) return
|
||||||
try {
|
navigate(new URL(window.location.toString()), true)
|
||||||
navigate(new URL(window.location.toString()), true)
|
|
||||||
} catch (e) {
|
|
||||||
window.location.reload()
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
const bufferPx = 150
|
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const slug = entry.target.id
|
const slug = entry.target.id
|
||||||
const tocEntryElement = document.querySelector(`a[data-for="${slug}"]`)
|
const tocEntryElements = document.querySelectorAll(`a[data-for="${slug}"]`)
|
||||||
const windowHeight = entry.rootBounds?.height
|
const windowHeight = entry.rootBounds?.height
|
||||||
if (windowHeight && tocEntryElement) {
|
if (windowHeight && tocEntryElements.length > 0) {
|
||||||
if (entry.boundingClientRect.y < windowHeight) {
|
if (entry.boundingClientRect.y < windowHeight) {
|
||||||
tocEntryElement.classList.add("in-view")
|
tocEntryElements.forEach((tocEntryElement) => tocEntryElement.classList.add("in-view"))
|
||||||
} else {
|
} else {
|
||||||
tocEntryElement.classList.remove("in-view")
|
tocEntryElements.forEach((tocEntryElement) => tocEntryElement.classList.remove("in-view"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,22 +22,18 @@ function toggleToc(this: HTMLElement) {
|
|||||||
const content = this.nextElementSibling as HTMLElement | undefined
|
const content = this.nextElementSibling as HTMLElement | undefined
|
||||||
if (!content) return
|
if (!content) return
|
||||||
content.classList.toggle("collapsed")
|
content.classList.toggle("collapsed")
|
||||||
content.style.maxHeight = content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupToc() {
|
function setupToc() {
|
||||||
const toc = document.getElementById("toc")
|
for (const toc of document.getElementsByClassName("toc")) {
|
||||||
if (toc) {
|
const button = toc.querySelector(".toc-header")
|
||||||
const collapsed = toc.classList.contains("collapsed")
|
const content = toc.querySelector(".toc-content")
|
||||||
const content = toc.nextElementSibling as HTMLElement | undefined
|
if (!button || !content) return
|
||||||
if (!content) return
|
button.addEventListener("click", toggleToc)
|
||||||
content.style.maxHeight = collapsed ? "0px" : content.scrollHeight + "px"
|
window.addCleanup(() => button.removeEventListener("click", toggleToc))
|
||||||
toc.addEventListener("click", toggleToc)
|
|
||||||
window.addCleanup(() => toc.removeEventListener("click", toggleToc))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("resize", setupToc)
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
setupToc()
|
setupToc()
|
||||||
|
|
||||||
|
@ -24,3 +24,23 @@ export function removeAllChildren(node: HTMLElement) {
|
|||||||
node.removeChild(node.firstChild)
|
node.removeChild(node.firstChild)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AliasRedirect emits HTML redirects which also have the link[rel="canonical"]
|
||||||
|
// containing the URL it's redirecting to.
|
||||||
|
// Extracting it here with regex is _probably_ faster than parsing the entire HTML
|
||||||
|
// with a DOMParser effectively twice (here and later in the SPA code), even if
|
||||||
|
// way less robust - we only care about our own generated redirects after all.
|
||||||
|
const canonicalRegex = /<link rel="canonical" href="([^"]*)">/
|
||||||
|
|
||||||
|
export async function fetchCanonical(url: URL): Promise<Response> {
|
||||||
|
const res = await fetch(`${url}`)
|
||||||
|
if (!res.headers.get("content-type")?.startsWith("text/html")) {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// reading the body can only be done once, so we need to clone the response
|
||||||
|
// to allow the caller to read it if it's was not a redirect
|
||||||
|
const text = await res.clone().text()
|
||||||
|
const [_, redirect] = text.match(canonicalRegex) ?? []
|
||||||
|
return redirect ? fetch(`${new URL(redirect, url)}`) : res
|
||||||
|
}
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
|
@use "../../styles/variables.scss" as *;
|
||||||
|
|
||||||
.backlinks {
|
.backlinks {
|
||||||
position: relative;
|
flex-direction: column;
|
||||||
|
|
||||||
& > h3 {
|
& > h3 {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
& > ul {
|
& > ul.overflow {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0.5rem 0;
|
margin: 0.5rem 0;
|
||||||
|
max-height: calc(100% - 2rem);
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
|
||||||
& > li {
|
& > li {
|
||||||
& > a {
|
& > a {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
color: var(--gray);
|
color: var(--gray);
|
||||||
|
|
||||||
&[show-comma="true"] {
|
&[show-comma="true"] {
|
||||||
> span:not(:last-child) {
|
> *:not(:last-child) {
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
|
@ -6,8 +6,9 @@
|
|||||||
border: none;
|
border: none;
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
margin: 0 10px;
|
margin: 0;
|
||||||
text-align: inherit;
|
text-align: inherit;
|
||||||
|
flex-shrink: 0;
|
||||||
|
|
||||||
& svg {
|
& svg {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -28,19 +29,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:root[saved-theme="dark"] .darkmode {
|
:root[saved-theme="dark"] .darkmode {
|
||||||
& > #dayIcon {
|
& > .dayIcon {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
& > #nightIcon {
|
& > .nightIcon {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:root .darkmode {
|
:root .darkmode {
|
||||||
& > #dayIcon {
|
& > .dayIcon {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
& > #nightIcon {
|
& > .nightIcon {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,97 @@
|
|||||||
@use "../../styles/variables.scss" as *;
|
@use "../../styles/variables.scss" as *;
|
||||||
|
|
||||||
button#explorer {
|
@media all and ($mobile) {
|
||||||
|
.page > #quartz-body {
|
||||||
|
// Shift page position when toggling Explorer on mobile.
|
||||||
|
& > :not(.sidebar.left:has(.explorer)) {
|
||||||
|
transition: transform 300ms ease-in-out;
|
||||||
|
}
|
||||||
|
&.lock-scroll > :not(.sidebar.left:has(.explorer)) {
|
||||||
|
transform: translateX(100dvw);
|
||||||
|
transition: transform 300ms ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sticky top bar (stays in place when scrolling down on mobile).
|
||||||
|
.sidebar.left:has(.explorer) {
|
||||||
|
box-sizing: border-box;
|
||||||
|
position: sticky;
|
||||||
|
background-color: var(--light);
|
||||||
|
padding: 1rem 0 1rem 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide-until-loaded ~ .explorer-content {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.explorer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-y: hidden;
|
||||||
|
|
||||||
|
min-height: 1.2rem;
|
||||||
|
flex: 0 1 auto;
|
||||||
|
&.collapsed {
|
||||||
|
flex: 0 1 1.2rem;
|
||||||
|
& .fold {
|
||||||
|
transform: rotateZ(-90deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .fold {
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
transition: transform 0.3s ease;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and ($mobile) {
|
||||||
|
order: -1;
|
||||||
|
height: initial;
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
align-self: flex-start;
|
||||||
|
margin-top: auto;
|
||||||
|
margin-bottom: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.mobile-explorer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.desktop-explorer {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and ($mobile) {
|
||||||
|
button.mobile-explorer {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.desktop-explorer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.desktop-only {
|
||||||
|
@media all and not ($mobile) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
svg {
|
||||||
|
pointer-events: all;
|
||||||
|
transition: transform 0.35s ease;
|
||||||
|
|
||||||
|
& > polyline {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button.mobile-explorer,
|
||||||
|
button.desktop-explorer {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
@ -15,74 +106,47 @@ button#explorer {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
& .fold {
|
|
||||||
margin-left: 0.5rem;
|
|
||||||
transition: transform 0.3s ease;
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.collapsed .fold {
|
|
||||||
transform: rotateZ(-90deg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.folder-outer {
|
.explorer-content {
|
||||||
display: grid;
|
|
||||||
grid-template-rows: 0fr;
|
|
||||||
transition: grid-template-rows 0.3s ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-outer.open {
|
|
||||||
grid-template-rows: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folder-outer > ul {
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
#explorer-content {
|
|
||||||
list-style: none;
|
list-style: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
max-height: none;
|
overflow-y: auto;
|
||||||
transition:
|
|
||||||
max-height 0.35s ease,
|
|
||||||
visibility 0s linear 0s;
|
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
visibility: visible;
|
|
||||||
|
|
||||||
&.collapsed {
|
|
||||||
transition:
|
|
||||||
max-height 0.35s ease,
|
|
||||||
visibility 0s linear 0.35s;
|
|
||||||
visibility: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.collapsed > .overflow::after {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
& ul {
|
& ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0.08rem 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
transition:
|
overscroll-behavior: contain;
|
||||||
max-height 0.35s ease,
|
|
||||||
transform 0.35s ease,
|
|
||||||
opacity 0.2s ease;
|
|
||||||
& li > a {
|
& li > a {
|
||||||
color: var(--dark);
|
color: var(--dark);
|
||||||
opacity: 0.75;
|
opacity: 0.75;
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
opacity: 1;
|
||||||
|
color: var(--tertiary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
svg {
|
.folder-outer {
|
||||||
pointer-events: all;
|
display: grid;
|
||||||
|
grid-template-rows: 0fr;
|
||||||
|
transition: grid-template-rows 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
& > polyline {
|
.folder-outer.open {
|
||||||
pointer-events: none;
|
grid-template-rows: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.folder-outer > ul {
|
||||||
|
overflow: hidden;
|
||||||
|
margin-left: 6px;
|
||||||
|
padding-left: 0.8rem;
|
||||||
|
border-left: 1px solid var(--lightgray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +199,7 @@ svg {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: transform 0.3s ease;
|
transition: transform 0.3s ease;
|
||||||
backface-visibility: visible;
|
backface-visibility: visible;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
li:has(> .folder-outer:not(.open)) > .folder-container > svg {
|
li:has(> .folder-outer:not(.open)) > .folder-container > svg {
|
||||||
@ -145,13 +210,61 @@ li:has(> .folder-outer:not(.open)) > .folder-container > svg {
|
|||||||
color: var(--tertiary);
|
color: var(--tertiary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.no-background::after {
|
.explorer {
|
||||||
background: none !important;
|
@media all and ($mobile) {
|
||||||
|
&.collapsed {
|
||||||
|
flex: 0 0 34px;
|
||||||
|
|
||||||
|
& > .explorer-content {
|
||||||
|
transform: translateX(-100vw);
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:not(.collapsed) {
|
||||||
|
flex: 0 0 34px;
|
||||||
|
|
||||||
|
& > .explorer-content {
|
||||||
|
transform: translateX(0);
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.explorer-content {
|
||||||
|
box-sizing: border-box;
|
||||||
|
z-index: 100;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
margin-top: 0;
|
||||||
|
background-color: var(--light);
|
||||||
|
max-width: 100vw;
|
||||||
|
width: 100%;
|
||||||
|
transform: translateX(-100vw);
|
||||||
|
transition:
|
||||||
|
transform 200ms ease,
|
||||||
|
visibility 200ms ease;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 4rem 0 2rem 0;
|
||||||
|
height: 100dvh;
|
||||||
|
max-height: 100dvh;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-explorer {
|
||||||
|
margin: 0;
|
||||||
|
padding: 5px;
|
||||||
|
z-index: 101;
|
||||||
|
|
||||||
|
.lucide-menu {
|
||||||
|
stroke: var(--darkgray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#explorer-end {
|
.mobile-no-scroll {
|
||||||
// needs height so IntersectionObserver gets triggered
|
@media all and ($mobile) {
|
||||||
height: 4px;
|
overflow: hidden;
|
||||||
// remove default margin from li
|
}
|
||||||
margin: 0;
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
& > #global-graph-icon {
|
& > .global-graph-icon {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
@ -38,7 +38,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
& > #global-graph-outer {
|
& > .global-graph-outer {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
left: 0;
|
left: 0;
|
||||||
@ -53,7 +53,7 @@
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
& > #global-graph-container {
|
& > .global-graph-container {
|
||||||
border: 1px solid var(--lightgray);
|
border: 1px solid var(--lightgray);
|
||||||
background-color: var(--light);
|
background-color: var(--light);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@ -65,7 +65,7 @@
|
|||||||
height: 80vh;
|
height: 80vh;
|
||||||
width: 80vw;
|
width: 80vw;
|
||||||
|
|
||||||
@media all and (max-width: $fullPageWidth) {
|
@media all and not ($desktop) {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|