Repository: jackyzha0/quartz Branch: v4 Commit: 59b58076016c Files: 270 Total size: 15.3 MB Directory structure: gitextract_71a7u_g6/ ├── .gitattributes ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.md │ │ └── feature_request.md │ ├── dependabot.yml │ ├── pull_request_template.md │ └── workflows/ │ ├── build-preview.yaml │ ├── ci.yaml │ ├── deploy-preview.yaml │ └── docker-build-push.yaml ├── .node-version ├── .npmrc ├── .prettierignore ├── .prettierrc ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── LICENSE.txt ├── README.md ├── content/ │ └── .gitkeep ├── docs/ │ ├── advanced/ │ │ ├── architecture.md │ │ ├── creating components.md │ │ ├── index.md │ │ ├── making plugins.md │ │ └── paths.md │ ├── authoring content.md │ ├── build.md │ ├── configuration.md │ ├── features/ │ │ ├── Citations.md │ │ ├── Docker Support.md │ │ ├── Latex.md │ │ ├── Mermaid diagrams.md │ │ ├── Obsidian compatibility.md │ │ ├── OxHugo compatibility.md │ │ ├── RSS Feed.md │ │ ├── Roam Research compatibility.md │ │ ├── SPA Routing.md │ │ ├── backlinks.md │ │ ├── breadcrumbs.md │ │ ├── callouts.md │ │ ├── comments.md │ │ ├── darkmode.md │ │ ├── explorer.md │ │ ├── folder and tag listings.md │ │ ├── full-text search.md │ │ ├── graph view.md │ │ ├── i18n.md │ │ ├── index.md │ │ ├── popover previews.md │ │ ├── private pages.md │ │ ├── reader mode.md │ │ ├── recent notes.md │ │ ├── social images.md │ │ ├── syntax highlighting.md │ │ ├── table of contents.md │ │ ├── upcoming features.md │ │ └── wikilinks.md │ ├── hosting.md │ ├── index.md │ ├── layout-components.md │ ├── layout.md │ ├── migrating from Quartz 3.md │ ├── philosophy.md │ ├── plugins/ │ │ ├── AliasRedirects.md │ │ ├── Assets.md │ │ ├── CNAME.md │ │ ├── Citations.md │ │ ├── ComponentResources.md │ │ ├── ContentIndex.md │ │ ├── ContentPage.md │ │ ├── CrawlLinks.md │ │ ├── CreatedModifiedDate.md │ │ ├── CustomOgImages.md │ │ ├── Description.md │ │ ├── ExplicitPublish.md │ │ ├── Favicon.md │ │ ├── FolderPage.md │ │ ├── Frontmatter.md │ │ ├── GitHubFlavoredMarkdown.md │ │ ├── HardLineBreaks.md │ │ ├── Latex.md │ │ ├── NotFoundPage.md │ │ ├── ObsidianFlavoredMarkdown.md │ │ ├── OxHugoFlavoredMarkdown.md │ │ ├── RemoveDrafts.md │ │ ├── RoamFlavoredMarkdown.md │ │ ├── Static.md │ │ ├── SyntaxHighlighting.md │ │ ├── TableOfContents.md │ │ ├── TagPage.md │ │ └── index.md │ ├── setting up your GitHub repository.md │ ├── showcase.md │ ├── tags/ │ │ ├── component.md │ │ └── plugin.md │ └── upgrading.md ├── globals.d.ts ├── index.d.ts ├── package.json ├── quartz/ │ ├── bootstrap-cli.mjs │ ├── bootstrap-worker.mjs │ ├── build.ts │ ├── cfg.ts │ ├── cli/ │ │ ├── args.js │ │ ├── constants.js │ │ ├── handlers.js │ │ └── helpers.js │ ├── components/ │ │ ├── ArticleTitle.tsx │ │ ├── Backlinks.tsx │ │ ├── Body.tsx │ │ ├── Breadcrumbs.tsx │ │ ├── Comments.tsx │ │ ├── ConditionalRender.tsx │ │ ├── ContentMeta.tsx │ │ ├── Darkmode.tsx │ │ ├── Date.tsx │ │ ├── DesktopOnly.tsx │ │ ├── Explorer.tsx │ │ ├── Flex.tsx │ │ ├── Footer.tsx │ │ ├── Graph.tsx │ │ ├── Head.tsx │ │ ├── Header.tsx │ │ ├── MobileOnly.tsx │ │ ├── OverflowList.tsx │ │ ├── PageList.tsx │ │ ├── PageTitle.tsx │ │ ├── ReaderMode.tsx │ │ ├── RecentNotes.tsx │ │ ├── Search.tsx │ │ ├── Spacer.tsx │ │ ├── TableOfContents.tsx │ │ ├── TagList.tsx │ │ ├── index.ts │ │ ├── pages/ │ │ │ ├── 404.tsx │ │ │ ├── Content.tsx │ │ │ ├── FolderContent.tsx │ │ │ └── TagContent.tsx │ │ ├── renderPage.tsx │ │ ├── scripts/ │ │ │ ├── callout.inline.ts │ │ │ ├── checkbox.inline.ts │ │ │ ├── clipboard.inline.ts │ │ │ ├── comments.inline.ts │ │ │ ├── darkmode.inline.ts │ │ │ ├── explorer.inline.ts │ │ │ ├── graph.inline.ts │ │ │ ├── mermaid.inline.ts │ │ │ ├── popover.inline.ts │ │ │ ├── readermode.inline.ts │ │ │ ├── search.inline.ts │ │ │ ├── search.test.ts │ │ │ ├── spa.inline.ts │ │ │ ├── toc.inline.ts │ │ │ └── util.ts │ │ ├── styles/ │ │ │ ├── backlinks.scss │ │ │ ├── breadcrumbs.scss │ │ │ ├── clipboard.scss │ │ │ ├── contentMeta.scss │ │ │ ├── darkmode.scss │ │ │ ├── explorer.scss │ │ │ ├── footer.scss │ │ │ ├── graph.scss │ │ │ ├── legacyToc.scss │ │ │ ├── listPage.scss │ │ │ ├── mermaid.inline.scss │ │ │ ├── popover.scss │ │ │ ├── readermode.scss │ │ │ ├── recentNotes.scss │ │ │ ├── search.scss │ │ │ └── toc.scss │ │ └── types.ts │ ├── i18n/ │ │ ├── index.ts │ │ └── locales/ │ │ ├── ar-SA.ts │ │ ├── ca-ES.ts │ │ ├── cs-CZ.ts │ │ ├── de-DE.ts │ │ ├── definition.ts │ │ ├── en-GB.ts │ │ ├── en-US.ts │ │ ├── es-ES.ts │ │ ├── fa-IR.ts │ │ ├── fi-FI.ts │ │ ├── fr-FR.ts │ │ ├── he-IL.ts │ │ ├── hu-HU.ts │ │ ├── id-ID.ts │ │ ├── it-IT.ts │ │ ├── ja-JP.ts │ │ ├── kk-KZ.ts │ │ ├── ko-KR.ts │ │ ├── lt-LT.ts │ │ ├── nb-NO.ts │ │ ├── nl-NL.ts │ │ ├── pl-PL.ts │ │ ├── pt-BR.ts │ │ ├── ro-RO.ts │ │ ├── ru-RU.ts │ │ ├── th-TH.ts │ │ ├── tr-TR.ts │ │ ├── uk-UA.ts │ │ ├── vi-VN.ts │ │ ├── zh-CN.ts │ │ └── zh-TW.ts │ ├── plugins/ │ │ ├── emitters/ │ │ │ ├── 404.tsx │ │ │ ├── aliases.ts │ │ │ ├── assets.ts │ │ │ ├── cname.ts │ │ │ ├── componentResources.ts │ │ │ ├── contentIndex.tsx │ │ │ ├── contentPage.tsx │ │ │ ├── favicon.ts │ │ │ ├── folderPage.tsx │ │ │ ├── helpers.ts │ │ │ ├── index.ts │ │ │ ├── ogImage.tsx │ │ │ ├── static.ts │ │ │ └── tagPage.tsx │ │ ├── filters/ │ │ │ ├── draft.ts │ │ │ ├── explicit.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── transformers/ │ │ │ ├── citations.ts │ │ │ ├── description.ts │ │ │ ├── frontmatter.ts │ │ │ ├── gfm.ts │ │ │ ├── index.ts │ │ │ ├── lastmod.ts │ │ │ ├── latex.ts │ │ │ ├── linebreaks.ts │ │ │ ├── links.ts │ │ │ ├── ofm.ts │ │ │ ├── oxhugofm.ts │ │ │ ├── roam.ts │ │ │ ├── syntax.ts │ │ │ └── toc.ts │ │ ├── types.ts │ │ └── vfile.ts │ ├── processors/ │ │ ├── emit.ts │ │ ├── filter.ts │ │ └── parse.ts │ ├── static/ │ │ └── giscus/ │ │ ├── dark.css │ │ └── light.css │ ├── styles/ │ │ ├── base.scss │ │ ├── callouts.scss │ │ ├── custom.scss │ │ ├── syntax.scss │ │ └── variables.scss │ ├── util/ │ │ ├── clone.ts │ │ ├── ctx.ts │ │ ├── emoji.ts │ │ ├── emojimap.json │ │ ├── escape.ts │ │ ├── fileTrie.test.ts │ │ ├── fileTrie.ts │ │ ├── glob.ts │ │ ├── jsx.tsx │ │ ├── lang.ts │ │ ├── log.ts │ │ ├── og.tsx │ │ ├── path.test.ts │ │ ├── path.ts │ │ ├── perf.ts │ │ ├── random.ts │ │ ├── resources.tsx │ │ ├── sourcemap.ts │ │ ├── theme.ts │ │ └── trace.ts │ └── worker.ts ├── quartz.config.ts ├── quartz.layout.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ * text=auto eol=lf ================================================ FILE: .github/FUNDING.yml ================================================ github: [jackyzha0] ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Something about Quartz isn't working the way you expect title: "" labels: bug assignees: "" --- **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** A clear and concise description of what you expected to happen. **Screenshots and Source** If applicable, add screenshots to help explain your problem. You can help speed up fixing the problem by either 1. providing a simple reproduction 2. linking to your Quartz repository where the problem can be observed **Desktop (please complete the following information):** - Quartz Version: [e.g. v4.1.2] - `node` Version: [e.g. v18.16] - `npm` version: [e.g. v10.1.0] - OS: [e.g. iOS] - Browser [e.g. chrome, safari] **Additional context** Add any other context about the problem here. ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: Feature request about: Suggest an idea or improvement for Quartz title: "" labels: enhancement assignees: "" --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .github/dependabot.yml ================================================ version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: 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: - "*" ================================================ FILE: .github/pull_request_template.md ================================================ ================================================ FILE: .github/workflows/build-preview.yaml ================================================ 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@v6 with: fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v6 with: node-version: 22 - name: Cache dependencies uses: actions/cache@v5 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@v6 with: name: preview-build path: public ================================================ FILE: .github/workflows/ci.yaml ================================================ name: Build and Test on: pull_request: branches: - v4 push: branches: - v4 workflow_dispatch: jobs: build-and-test: if: ${{ github.repository == 'jackyzha0/quartz' }} strategy: matrix: os: [windows-latest, macos-latest, ubuntu-latest] runs-on: ${{ matrix.os }} permissions: contents: write steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v6 with: node-version: 22 - name: Cache dependencies uses: actions/cache@v5 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: Test run: npm test - name: Ensure Quartz builds, check bundle info run: npx quartz build --bundleInfo -d docs publish-tag: if: ${{ github.repository == 'jackyzha0/quartz' && github.ref == 'refs/heads/v4' }} runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v6 with: node-version: 22 - name: Get package version run: node -p -e '`PACKAGE_VERSION=${require("./package.json").version}`' >> $GITHUB_ENV - name: Create release tag uses: pkgdeps/git-tag-action@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} github_repo: ${{ github.repository }} version: ${{ env.PACKAGE_VERSION }} git_commit_sha: ${{ github.sha }} git_tag_prefix: "v" ================================================ FILE: .github/workflows/deploy-preview.yaml ================================================ 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@v7 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 }} ================================================ FILE: .github/workflows/docker-build-push.yaml ================================================ 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@v6 with: fetch-depth: 1 - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v5.4.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@v4.0.0 - 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 ================================================ FILE: .node-version ================================================ v22.16.0 ================================================ FILE: .npmrc ================================================ engine-strict=true ================================================ FILE: .prettierignore ================================================ public node_modules .quartz-cache ================================================ FILE: .prettierrc ================================================ { "printWidth": 100, "quoteProps": "as-needed", "trailingComma": "all", "tabWidth": 2, "semi": false } ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Citizen Code of Conduct ## 1. Purpose A primary goal of the Quartz community is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. We invite all those who participate in the Quartz community to help us create safe and positive experiences for everyone. ## 2. Open [Source/Culture/Tech] Citizenship A supplemental goal of this Code of Conduct is to increase open [source/culture/tech] citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. ## 3. Expected Behavior The following behaviors are expected and requested of all community members: - Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. - Exercise consideration and respect in your speech and actions. - Attempt collaboration before conflict. - Refrain from demeaning, discriminatory, or harassing behavior and speech. - Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. - Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. ## 4. Unacceptable Behavior The following behaviors are considered harassment and are unacceptable within our community: - Violence, threats of violence or violent language directed against another person. - Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. - Posting or displaying sexually explicit or violent material. - Posting or threatening to post other people's personally identifying information ("doxing"). - Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. - Inappropriate photography or recording. - Inappropriate physical contact. You should have someone's consent before touching them. - Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. - Deliberate intimidation, stalking or following (online or in person). - Advocating for, or encouraging, any of the above behavior. - Sustained disruption of community events, including talks and presentations. ## 5. Weapons Policy No weapons will be allowed at Quartz community events, community spaces, or in other spaces covered by the scope of this Code of Conduct. Weapons include but are not limited to guns, explosives (including fireworks), and large knives such as those used for hunting or display, as well as any other item used for the purpose of causing injury or harm to others. Anyone seen in possession of one of these items will be asked to leave immediately, and will only be allowed to return without the weapon. Community members are further expected to comply with all state and local laws on this matter. ## 6. Consequences of Unacceptable Behavior Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. Anyone asked to stop unacceptable behavior is expected to comply immediately. If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). ## 7. Reporting Guidelines If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. j.zhao2k19@gmail.com. Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. ## 8. Addressing Grievances If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify @jackyzha0 with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. ## 9. Scope We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business. This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. ## 10. Contact info j.zhao2k19@gmail.com ## 11. License and attribution The Citizen Code of Conduct is distributed by [Stumptown Syndicate](http://stumptownsyndicate.org) under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). _Revision 2.3. Posted 6 March 2017._ _Revision 2.2. Posted 4 February 2016._ _Revision 2.1. Posted 23 June 2014._ _Revision 2.0, adopted by the [Stumptown Syndicate](http://stumptownsyndicate.org) board on 10 January 2013. Posted 17 March 2013._ ================================================ FILE: Dockerfile ================================================ FROM node:22-slim AS builder WORKDIR /usr/src/app COPY package.json . COPY package-lock.json* . RUN npm ci FROM node:22-slim WORKDIR /usr/src/app COPY --from=builder /usr/src/app/ /usr/src/app/ COPY . . CMD ["npx", "quartz", "build", "--serve"] ================================================ FILE: LICENSE.txt ================================================ MIT License Copyright (c) 2021 jackyzha0 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Quartz v4 > “[One] who works with the door open gets all kinds of interruptions, but [they] also occasionally gets clues as to what the world is and what might be important.” — Richard Hamming Quartz is a set of tools that helps you publish your [digital garden](https://jzhao.xyz/posts/networked-thought) and notes as a website for free. 🔗 Read the documentation and get started: https://quartz.jzhao.xyz/ [Join the Discord Community](https://discord.gg/cRFFHYye7t) ## Sponsors

================================================ FILE: content/.gitkeep ================================================ ================================================ FILE: docs/advanced/architecture.md ================================================ --- title: Architecture --- Quartz is a static site generator. How does it work? This question is best answered by tracing what happens when a user (you!) runs `npx quartz build` in the command line: ## On the server 1. After running `npx quartz build`, npm will look at `package.json` to find the `bin` entry for `quartz` which points at `./quartz/bootstrap-cli.mjs`. 2. This file has a [shebang]() line at the top which tells npm to execute it using Node. 3. `bootstrap-cli.mjs` is responsible for a few things: 1. Parsing the command-line arguments using [yargs](http://yargs.js.org/). 2. Transpiling and bundling the rest of Quartz (which is in Typescript) to regular JavaScript using [esbuild](https://esbuild.github.io/). The `esbuild` configuration here is slightly special as it also handles `.scss` file imports using [esbuild-sass-plugin v2](https://www.npmjs.com/package/esbuild-sass-plugin). Additionally, we bundle 'inline' client-side scripts (any `.inline.ts` file) that components declare using a custom `esbuild` plugin that runs another instance of `esbuild` which bundles for the browser instead of `node`. Modules of both types are imported as plain text. 3. Running the local preview server if `--serve` is set. This starts two servers: 1. A WebSocket server on port 3001 to handle hot-reload signals. This tracks all inbound connections and sends a 'rebuild' message a server-side change is detected (either content or configuration). 2. An HTTP file-server on a user defined port (normally 8080) to serve the actual website files. 4. If the `--serve` flag is set, it also starts a file watcher to detect source-code changes (e.g. anything that is `.ts`, `.tsx`, `.scss`, or packager files). On a change, we rebuild the module (step 2 above) using esbuild's [rebuild API](https://esbuild.github.io/api/#rebuild) which drastically reduces the build times. 5. After transpiling the main Quartz build module (`quartz/build.ts`), we write it to a cache file `.quartz-cache/transpiled-build.mjs` and then dynamically import this using `await import(cacheFile)`. However, we need to be pretty smart about how to bust Node's [import cache](https://github.com/nodejs/modules/issues/307) so we add a random query string to fake Node into thinking it's a new module. This does, however, cause memory leaks so we just hope that the user doesn't hot-reload their configuration too many times in a single session :)) (it leaks about ~350kB memory on each reload). After importing the module, we then invoke it, passing in the command line arguments we parsed earlier along with a callback function to signal the client to refresh. 4. In `build.ts`, we start by installing source map support manually to account for the query string cache busting hack we introduced earlier. Then, we start processing content: 1. Clean the output directory. 2. Recursively glob all files in the `content` folder, respecting the `.gitignore`. 3. Parse the Markdown files. 1. Quartz detects the number of threads available and chooses to spawn worker threads if there are >128 pieces of content to parse (rough heuristic). If it needs to spawn workers, it will invoke esbuild again to transpile the worker script `quartz/worker.ts`. Then, a work-stealing [workerpool](https://www.npmjs.com/package/workerpool) is then created and batches of 128 files are assigned to workers. 2. Each worker (or just the main thread if there is no concurrency) creates a [unified](https://github.com/unifiedjs/unified) parser based off of the plugins defined in the [[configuration]]. 3. Parsing has three steps: 1. Read the file into a [vfile](https://github.com/vfile/vfile). 2. Applied plugin-defined text transformations over the content. 3. Slugify the file path and store it in the data for the file. See the page on [[paths]] for more details about how path logic works in Quartz (spoiler: its complicated). 4. Markdown parsing using [remark-parse](https://www.npmjs.com/package/remark-parse) (text to [mdast](https://github.com/syntax-tree/mdast)). 5. Apply plugin-defined Markdown-to-Markdown transformations. 6. Convert Markdown into HTML using [remark-rehype](https://github.com/remarkjs/remark-rehype) ([mdast](https://github.com/syntax-tree/mdast) to [hast](https://github.com/syntax-tree/hast)). 7. Apply plugin-defined HTML-to-HTML transformations. 4. Filter out unwanted content using plugins. 5. Emit files using plugins. 1. Gather all the static resources (e.g. external CSS, JS modules, etc.) each emitter plugin declares. 2. Emitters that emit HTML files do a bit of extra work here as they need to transform the [hast](https://github.com/syntax-tree/hast) produced in the parse step to JSX. This is done using [hast-util-to-jsx-runtime](https://github.com/syntax-tree/hast-util-to-jsx-runtime) with the [Preact](https://preactjs.com/) runtime. Finally, the JSX is rendered to HTML using [preact-render-to-string](https://github.com/preactjs/preact-render-to-string) which statically renders the JSX to HTML (i.e. doesn't care about `useState`, `useEffect`, or any other React/Preact interactive bits). Here, we also do a bunch of fun stuff like assemble the page [[layout]] from `quartz.layout.ts`, assemble all the inline scripts that actually get shipped to the client, and all the transpiled styles. The bulk of this logic can be found in `quartz/components/renderPage.tsx`. Other fun things of note: 1. CSS is minified and transformed using [Lightning CSS](https://github.com/parcel-bundler/lightningcss) to add vendor prefixes and do syntax lowering. 2. Scripts are split into `beforeDOMLoaded` and `afterDOMLoaded` and are inserted in the `` and `` respectively. 3. Finally, each emitter plugin is responsible for emitting and writing it's own emitted files to disk. 6. If the `--serve` flag was detected, we also set up another file watcher to detect content changes (only `.md` files). We keep a content map that tracks the parsed AST and plugin data for each slug and update this on file changes. Newly added or modified paths are rebuilt and added to the content map. Then, all the filters and emitters are run over the resulting content map. This file watcher is debounced with a threshold of 250ms. On success, we send a client refresh signal using the passed in callback function. ## On the client 1. The browser opens a Quartz page and loads the HTML. The `` also links to page styles (emitted to `public/index.css`) and page-critical JS (emitted to `public/prescript.js`) 2. Then, once the body is loaded, the browser loads the non-critical JS (emitted to `public/postscript.js`) 3. Once the page is done loading, the page will then dispatch a custom synthetic browser event `"nav"`. This is used so client-side scripts declared by components can 'setup' anything that requires access to the page DOM. 1. If the [[SPA Routing|enableSPA option]] is enabled in the [[configuration]], this `"nav"` event is also fired on any client-navigation to allow for components to unregister and reregister any event handlers and state. 2. If it's not, we wire up the `"nav"` event to just be fired a single time after page load to allow for consistency across how state is setup across both SPA and non-SPA contexts. The architecture and design of the plugin system was intentionally left pretty vague here as this is described in much more depth in the guide on [[making plugins|making your own plugin]]. ================================================ FILE: docs/advanced/creating components.md ================================================ --- title: Creating your own Quartz components --- > [!warning] > This guide assumes you have experience writing JavaScript and are familiar with TypeScript. Normally on the web, we write layout code using HTML which looks something like the following: ```html

An article header

Some content

``` This piece of HTML represents an article with a leading header that says "An article header" and a paragraph that contains the text "Some content". This is combined with CSS to style the page and JavaScript to add interactivity. However, HTML doesn't let you create reusable templates. If you wanted to create a new page, you would need to copy and paste the above snippet and edit the header and content yourself. This isn't great if we have a lot of content on our site that shares a lot of similar layout. The smart people who created React also had similar complaints and invented the concept of Components -- JavaScript functions that return JSX -- to solve the code duplication problem. In effect, components allow you to write a JavaScript function that takes some data and produces HTML as an output. **While Quartz doesn't use React, it uses the same component concept to allow you to easily express layout templates in your Quartz site.** ## An Example Component ### Constructor Component files are written in `.tsx` files that live in the `quartz/components` folder. These are re-exported in `quartz/components/index.ts` so you can use them in layouts and other components more easily. Each component file should have a default export that satisfies the `QuartzComponentConstructor` function signature. It's a function that takes in a single optional parameter `opts` and returns a Quartz Component. The type of the parameters `opts` is defined by the interface `Options` which you as the component creator also decide. In your component, you can use the values from the configuration option to change the rendering behaviour inside of your component. For example, the component in the code snippet below will not render if the `favouriteNumber` option is below 0. ```tsx {11-17} interface Options { favouriteNumber: number } const defaultOptions: Options = { favouriteNumber: 42, } export default ((userOpts?: Options) => { const opts = { ...userOpts, ...defaultOpts } function YourComponent(props: QuartzComponentProps) { if (opts.favouriteNumber < 0) { return null } return

My favourite number is {opts.favouriteNumber}

} return YourComponent }) satisfies QuartzComponentConstructor ``` ### Props The Quartz component itself (lines 11-17 highlighted above) looks like a React component. It takes in properties (sometimes called [props](https://react.dev/learn/passing-props-to-a-component)) and returns JSX. All Quartz components accept the same set of props: ```tsx title="quartz/components/types.ts" // simplified for sake of demonstration export type QuartzComponentProps = { fileData: QuartzPluginData cfg: GlobalConfiguration tree: Node allFiles: QuartzPluginData[] displayClass?: "mobile-only" | "desktop-only" } ``` - `fileData`: Any metadata [[making plugins|plugins]] may have added to the current page. - `fileData.slug`: slug of the current page. - `fileData.frontmatter`: any frontmatter parsed. - `cfg`: The `configuration` field in `quartz.config.ts`. - `tree`: the resulting [HTML AST](https://github.com/syntax-tree/hast) after processing and transforming the file. This is useful if you'd like to render the content using [hast-util-to-jsx-runtime](https://github.com/syntax-tree/hast-util-to-jsx-runtime) (you can find an example of this in `quartz/components/pages/Content.tsx`). - `allFiles`: Metadata for all files that have been parsed. Useful for doing page listings or figuring out the overall site structure. - `displayClass`: a utility class that indicates a preference from the user about how to render it in a mobile or desktop setting. Helpful if you want to conditionally hide a component on mobile or desktop. ### Styling Quartz components can also define a `.css` property on the actual function component which will get picked up by Quartz. This is expected to be a CSS string which can either be inlined or imported from a `.scss` file. Note that inlined styles **must** be plain vanilla CSS: ```tsx {6-10} title="quartz/components/YourComponent.tsx" export default (() => { function YourComponent() { return

Example Component

} YourComponent.css = ` p.red-text { color: red; } ` return YourComponent }) satisfies QuartzComponentConstructor ``` Imported styles, however, can be from SCSS files: ```tsx {1-2,9} title="quartz/components/YourComponent.tsx" // assuming your stylesheet is in quartz/components/styles/YourComponent.scss import styles from "./styles/YourComponent.scss" export default (() => { function YourComponent() { return

Example Component

} YourComponent.css = styles return YourComponent }) satisfies QuartzComponentConstructor ``` > [!warning] > Quartz does not use CSS modules so any styles you declare here apply _globally_. If you only want it to apply to your component, make sure you use specific class names and selectors. ### Scripts and Interactivity What about interactivity? Suppose you want to add an-click handler for example. Like the `.css` property on the component, you can also declare `.beforeDOMLoaded` and `.afterDOMLoaded` properties that are strings that contain the script. ```tsx title="quartz/components/YourComponent.tsx" export default (() => { function YourComponent() { return } YourComponent.beforeDOMLoaded = ` console.log("hello from before the page loads!") ` YourComponent.afterDOMLoaded = ` document.getElementById('btn').onclick = () => { alert('button clicked!') } ` return YourComponent }) satisfies QuartzComponentConstructor ``` > [!hint] > For those coming from React, Quartz components are different from React components in that it only uses JSX for templating and layout. Hooks like `useEffect`, `useState`, etc. are not rendered and other properties that accept functions like `onClick` handlers will not work. Instead, do it using a regular JS script that modifies the DOM element directly. As the names suggest, the `.beforeDOMLoaded` scripts are executed _before_ the page is done loading so it doesn't have access to any elements on the page. This is mostly used to prefetch any critical data. The `.afterDOMLoaded` script executes once the page has been completely loaded. This is a good place to setup anything that should last for the duration of a site visit (e.g. getting something saved from local storage). If you need to create an `afterDOMLoaded` script that depends on _page specific_ elements that may change when navigating to a new page, you can listen for the `"nav"` event that gets fired whenever a page loads (which may happen on navigation if [[SPA Routing]] is enabled). ```ts document.addEventListener("nav", () => { // do page specific logic here // e.g. attach event listeners const toggleSwitch = document.querySelector("#switch") as HTMLInputElement toggleSwitch.addEventListener("change", switchTheme) window.addCleanup(() => toggleSwitch.removeEventListener("change", switchTheme)) }) ``` 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. This will get called on page navigation. #### Importing Code Of course, it isn't always practical (nor desired!) to write your code as a string literal in the component. Quartz supports importing component code through `.inline.ts` files. ```tsx title="quartz/components/YourComponent.tsx" // @ts-ignore: typescript doesn't know about our inline bundling system // so we need to silence the error import script from "./scripts/graph.inline" export default (() => { function YourComponent() { return } YourComponent.afterDOMLoaded = script return YourComponent }) satisfies QuartzComponentConstructor ``` ```ts title="quartz/components/scripts/graph.inline.ts" // any imports here are bundled for the browser import * as d3 from "d3" document.getElementById("btn").onclick = () => { alert("button clicked!") } ``` Additionally, like what is shown in the example above, you can import packages in `.inline.ts` files. This will be bundled by Quartz and included in the actual script. ### Using a Component After creating your custom component, re-export it in `quartz/components/index.ts`: ```ts title="quartz/components/index.ts" {4,10} import ArticleTitle from "./ArticleTitle" import Content from "./pages/Content" import Darkmode from "./Darkmode" import YourComponent from "./YourComponent" export { ArticleTitle, Content, Darkmode, YourComponent } ``` Then, you can use it like any other component in `quartz.layout.ts` via `Component.YourComponent()`. See the [[configuration#Layout|layout]] section for more details. As Quartz components are just functions that return React components, you can compositionally use them in other Quartz components. ```tsx title="quartz/components/AnotherComponent.tsx" import YourComponentConstructor from "./YourComponent" export default (() => { const YourComponent = YourComponentConstructor() function AnotherComponent(props: QuartzComponentProps) { return (

It's nested!

) } return AnotherComponent }) satisfies QuartzComponentConstructor ``` > [!hint] > Look in `quartz/components` for more examples of components in Quartz as reference for your own components! ================================================ FILE: docs/advanced/index.md ================================================ --- title: "Advanced" --- ================================================ FILE: docs/advanced/making plugins.md ================================================ --- title: Making your own plugins --- > [!warning] > This part of the documentation will assume you have working knowledge in TypeScript and will include code snippets that describe the interface of what Quartz plugins should look like. Quartz's plugins are a series of transformations over content. This is illustrated in the diagram of the processing pipeline below: ![[quartz transform pipeline.png]] All plugins are defined as a function that takes in a single parameter for options `type OptionType = object | undefined` and return an object that corresponds to the type of plugin it is. ```ts type OptionType = object | undefined type QuartzPlugin = (opts?: Options) => QuartzPluginInstance type QuartzPluginInstance = | QuartzTransformerPluginInstance | QuartzFilterPluginInstance | QuartzEmitterPluginInstance ``` The following sections will go into detail for what methods can be implemented for each plugin type. Before we do that, let's clarify a few more ambiguous types: - `BuildCtx` is defined in `quartz/ctx.ts`. It consists of - `argv`: The command line arguments passed to the Quartz [[build]] command - `cfg`: The full Quartz [[configuration]] - `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 - `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. - `additionalHead`: a list of JSX elements or functions that return JSX elements to be added to the `` tag of the page. Functions receive the page's data as an argument and can conditionally render elements. ## Transformers Transformers **map** over content, taking a Markdown file and outputting modified content or adding metadata to the file itself. ```ts export type QuartzTransformerPluginInstance = { name: string textTransform?: (ctx: BuildCtx, src: string) => string markdownPlugins?: (ctx: BuildCtx) => PluggableList htmlPlugins?: (ctx: BuildCtx) => PluggableList externalResources?: (ctx: BuildCtx) => Partial } ``` All transformer plugins must define at least a `name` field to register the plugin and a few optional functions that allow you to hook into various parts of transforming a single Markdown file. - `textTransform` performs a text-to-text transformation _before_ a file is parsed into the [Markdown AST](https://github.com/syntax-tree/mdast). - `markdownPlugins` defines a list of [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md). `remark` is a tool that transforms Markdown to Markdown in a structured way. - `htmlPlugins` defines a list of [rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md). Similar to how `remark` works, `rehype` is a tool that transforms HTML to HTML in a structured way. - `externalResources` defines any external resources the plugin may need to load on the client-side for it to work properly. Normally for both `remark` and `rehype`, you can find existing plugins that you can use to . If you'd like to create your own `remark` or `rehype` plugin, checkout the [guide to creating a plugin](https://unifiedjs.com/learn/guide/create-a-plugin/) using `unified` (the underlying AST parser and transformer library). A good example of a transformer plugin that borrows from the `remark` and `rehype` ecosystems is the [[plugins/Latex|Latex]] plugin: ```ts title="quartz/plugins/transformers/latex.ts" import remarkMath from "remark-math" import rehypeKatex from "rehype-katex" import rehypeMathjax from "rehype-mathjax/svg" import { QuartzTransformerPlugin } from "../types" interface Options { renderEngine: "katex" | "mathjax" } export const Latex: QuartzTransformerPlugin = (opts?: Options) => { const engine = opts?.renderEngine ?? "katex" return { name: "Latex", markdownPlugins() { return [remarkMath] }, htmlPlugins() { if (engine === "katex") { // if you need to pass options into a plugin, you // can use a tuple of [plugin, options] return [[rehypeKatex, { output: "html" }]] } else { return [rehypeMathjax] } }, externalResources() { if (engine === "katex") { return { css: [ { // base css content: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css", }, ], js: [ { // fix copy behaviour: https://github.com/KaTeX/KaTeX/blob/main/contrib/copy-tex/README.md src: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/contrib/copy-tex.min.js", loadTime: "afterDOMReady", contentType: "external", }, ], } } }, } } ``` Another common thing that transformer plugins will do is parse a file and add extra data for that file: ```ts export const AddWordCount: QuartzTransformerPlugin = () => { return { name: "AddWordCount", markdownPlugins() { return [ () => { return (tree, file) => { // tree is an `mdast` root element // file is a `vfile` const text = file.value const words = text.split(" ").length file.data.wordcount = words } }, ] }, } } // tell typescript about our custom data fields we are adding // other plugins will then also be aware of this data field declare module "vfile" { interface DataMap { wordcount: number } } ``` Finally, you can also perform transformations over Markdown or HTML ASTs using the `visit` function from the `unist-util-visit` package or the `findAndReplace` function from the `mdast-util-find-and-replace` package. ```ts export const TextTransforms: QuartzTransformerPlugin = () => { return { name: "TextTransforms", markdownPlugins() { return [() => { return (tree, file) => { // replace _text_ with the italics version findAndReplace(tree, /_(.+)_/, (_value: string, ...capture: string[]) => { // inner is the text inside of the () of the regex const [inner] = capture // return an mdast node // https://github.com/syntax-tree/mdast return { type: "emphasis", children: [{ type: 'text', value: inner }] } }) // remove all links (replace with just the link content) // match by 'type' field on an mdast node // https://github.com/syntax-tree/mdast#link in this example visit(tree, "link", (link: Link) => { return { type: "paragraph" children: [{ type: 'text', value: link.title }] } }) } }] } } } ``` All transformer plugins can be found under `quartz/plugins/transformers`. If you decide to write your own transformer plugin, don't forget to re-export it under `quartz/plugins/transformers/index.ts` A parting word: transformer plugins are quite complex so don't worry if you don't get them right away. Take a look at the built in transformers and see how they operate over content to get a better sense for how to accomplish what you are trying to do. ## Filters Filters **filter** content, taking the output of all the transformers and determining what files to actually keep and what to discard. ```ts export type QuartzFilterPlugin = ( opts?: Options, ) => QuartzFilterPluginInstance export type QuartzFilterPluginInstance = { name: string shouldPublish(ctx: BuildCtx, content: ProcessedContent): boolean } ``` A filter plugin must define a `name` field and a `shouldPublish` function that takes in a piece of content that has been processed by all the transformers and returns a `true` or `false` depending on whether it should be passed to the emitter plugins or not. For example, here is the built-in plugin for removing drafts: ```ts title="quartz/plugins/filters/draft.ts" import { QuartzFilterPlugin } from "../types" export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({ name: "RemoveDrafts", shouldPublish(_ctx, [_tree, vfile]) { // uses frontmatter parsed from transformers const draftFlag: boolean = vfile.data?.frontmatter?.draft ?? false return !draftFlag }, }) ``` ## Emitters Emitters **reduce** over content, taking in a list of all the transformed and filtered content and creating output files. ```ts export type QuartzEmitterPlugin = ( opts?: Options, ) => QuartzEmitterPluginInstance export type QuartzEmitterPluginInstance = { name: string emit( ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources, ): Promise | AsyncGenerator partialEmit?( ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources, changeEvents: ChangeEvent[], ): Promise | AsyncGenerator | null getQuartzComponents(ctx: BuildCtx): QuartzComponent[] } ``` 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: ```ts export type WriteOptions = (data: { // the build context ctx: BuildCtx // the name of the file to emit (not including the file extension) slug: FullSlug // the file extension ext: `.${string}` | "" // the file content to add content: string }) => Promise ``` This is a thin wrapper around writing to the appropriate output folder and ensuring that intermediate directories exist. If you choose to use the native Node `fs` APIs, ensure you emit to the `argv.output` folder as well. If you are creating an emitter plugin that needs to render components, there are three more things to be aware of: - Your component should use `getQuartzComponents` to declare a list of `QuartzComponents` that it uses to construct the page. See the page on [[creating components]] for more information. - You can use the `renderPage` function defined in `quartz/components/renderPage.tsx` to render Quartz components into HTML. - If you need to render an HTML AST to JSX, you can use the `htmlToJsx` function from `quartz/util/jsx.ts`. An example of this can be found in `quartz/components/pages/Content.tsx`. For example, the following is a simplified version of the content page plugin that renders every single page. ```tsx title="quartz/plugins/emitters/contentPage.tsx" export const ContentPage: QuartzEmitterPlugin = () => { // construct the layout const layout: FullPageLayout = { ...sharedPageComponents, ...defaultContentPageLayout, pageBody: Content(), } const { head, header, beforeBody, pageBody, afterBody, left, right, footer } = layout return { name: "ContentPage", getQuartzComponents() { return [head, ...header, ...beforeBody, pageBody, ...afterBody, ...left, ...right, footer] }, async emit(ctx, content, resources, emit): Promise { const cfg = ctx.cfg.configuration const fps: FilePath[] = [] const allFiles = content.map((c) => c[1].data) for (const [tree, file] of content) { const slug = canonicalizeServer(file.data.slug!) const externalResources = pageResources(slug, file.data, resources) const componentData: QuartzComponentProps = { fileData: file.data, externalResources, cfg, children: [], tree, allFiles, } const content = renderPage(cfg, slug, componentData, opts, externalResources) const fp = await emit({ content, slug: file.data.slug!, ext: ".html", }) fps.push(fp) } return fps }, } } ``` Note that it takes in a `FullPageLayout` as the options. It's made by combining a `SharedLayout` and a `PageLayout` both of which are provided through the `quartz.layout.ts` file. > [!hint] > Look in `quartz/plugins` for more examples of plugins in Quartz as reference for your own plugins! ================================================ FILE: docs/advanced/paths.md ================================================ --- title: Paths in Quartz --- Paths are pretty complex to reason about because, especially for a static site generator, they can come from so many places. A full file path to a piece of content? Also a path. What about a slug for a piece of content? Yet another path. It would be silly to type these all as `string` and call it a day as it's pretty common to accidentally mistake one type of path for another. Unfortunately, TypeScript does not have [nominal types](https://en.wikipedia.org/wiki/Nominal_type_system) for type aliases meaning even if you made custom types of a server-side slug or a client-slug slug, you can still accidentally assign one to another and TypeScript wouldn't catch it. Luckily, we can mimic nominal typing using [brands](https://www.typescriptlang.org/play#example/nominal-typing). ```typescript // instead of type FullSlug = string // we do type FullSlug = string & { __brand: "full" } // that way, the following will fail typechecking const slug: FullSlug = "some random string" ``` While this prevents most typing mistakes _within_ our nominal typing system (e.g. mistaking a server slug for a client slug), it doesn't prevent us from _accidentally_ mistaking a string for a client slug when we forcibly cast it. Thus, we still need to be careful when casting from a string to one of these nominal types in the 'entrypoints', illustrated with hexagon shapes in the diagram below. The following diagram draws the relationships between all the path sources, nominal path types, and what functions in `quartz/path.ts` convert between them. ```mermaid graph LR Browser{{Browser}} --> Window{{Body}} & LinkElement{{Link Element}} Window --"getFullSlug()"--> FullSlug[Full Slug] LinkElement --".href"--> Relative[Relative URL] FullSlug --"simplifySlug()" --> SimpleSlug[Simple Slug] SimpleSlug --"pathToRoot()"--> Relative SimpleSlug --"resolveRelative()" --> Relative MD{{Markdown File}} --> FilePath{{File Path}} & Links[Markdown links] Links --"transformLink()"--> Relative FilePath --"slugifyFilePath()"--> FullSlug[Full Slug] style FullSlug stroke-width:4px ``` Here are the main types of slugs with a rough description of each type of path: - `FilePath`: a real file path to a file on disk. Cannot be relative and must have a file extension. - `FullSlug`: cannot be relative and may not have leading or trailing slashes. It can have `index` as it's last segment. Use this wherever possible is it's the most 'general' interpretation of a slug. - `SimpleSlug`: cannot be relative and shouldn't have `/index` as an ending or a file extension. It _can_ however have a trailing slash to indicate a folder path. - `RelativeURL`: must start with `.` or `..` to indicate it's a relative URL. Shouldn't have `/index` as an ending or a file extension but can contain a trailing slash. To get a clearer picture of how these relate to each other, take a look at the path tests in `quartz/util/path.test.ts`. ================================================ FILE: docs/authoring content.md ================================================ --- title: Authoring Content --- All of the content in your Quartz should go in the `/content` folder. The content for the home page of your Quartz lives in `content/index.md`. If you've [[index#🪴 Get Started|setup Quartz]] already, this folder should already be initialized. Any Markdown in this folder will get processed by Quartz. It is recommended that you use [Obsidian](https://obsidian.md/) as a way to edit and maintain your Quartz. It comes with a nice editor and graphical interface to preview, edit, and link your local files and attachments. Got everything setup? Let's [[build]] and preview your Quartz locally! ## Syntax As Quartz uses Markdown files as the main way of writing content, it fully supports Markdown syntax. By default, Quartz also ships with a few syntax extensions like [Github Flavored Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) (footnotes, strikethrough, tables, tasklists) and [Obsidian Flavored Markdown](https://help.obsidian.md/Editing+and+formatting/Obsidian+Flavored+Markdown) ([[callouts]], [[wikilinks]]). Additionally, Quartz also allows you to specify additional metadata in your notes called **frontmatter**. ```md title="content/note.md" --- title: Example Title draft: false tags: - example-tag --- The rest of your content lives here. You can use **Markdown** here :) ``` Some common frontmatter fields that are natively supported by Quartz: - `title`: Title of the page. If it isn't provided, Quartz will use the name of the file as the title. - `description`: Description of the page used for link previews. - `permalink`: A custom URL for the page that will remain constant even if the path to the file changes. - `aliases`: Other names for this note. This is a list of strings. - `tags`: Tags for this note. - `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. See [[Frontmatter]] for a complete list of frontmatter. ## Syncing your Content When your Quartz is at a point you're happy with, you can save your changes to GitHub. First, make sure you've [[setting up your GitHub repository|already setup your GitHub repository]] and then do `npx quartz sync`. ## Customization Frontmatter parsing for `title`, `tags`, `aliases` and `cssclasses` is a functionality of the [[Frontmatter]] plugin, `date` is handled by the [[CreatedModifiedDate]] plugin and `description` by the [[Description]] plugin. See the plugin pages for customization options. ================================================ FILE: docs/build.md ================================================ --- title: "Building your Quartz" --- Once you've [[index#🪴 Get Started|initialized]] Quartz, let's see what it looks like locally: ```bash npx quartz build --serve ``` This will start a local web server to run your Quartz on your computer. Open a web browser and visit `http://localhost:8080/` to view it. > [!hint] Flags and options > For full help options, you can run `npx quartz build --help`. > > Most of these have sensible defaults but you can override them if you have a custom setup: > > - `-d` or `--directory`: the content folder. This is normally just `content` > - `-v` or `--verbose`: print out extra logging information > - `-o` or `--output`: the output folder. This is normally just `public` > - `--serve`: run a local hot-reloading server to preview your Quartz > - `--port`: what port to run the local preview server on > - `--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]]. ================================================ FILE: docs/configuration.md ================================================ --- title: Configuration --- Quartz is meant to be extremely configurable, even if you don't know any coding. Most of the configuration you should need can be done by just editing `quartz.config.ts` or changing [[layout|the layout]] in `quartz.layout.ts`. > [!tip] > If you edit Quartz configuration using a text-editor that has TypeScript language support like VSCode, it will warn you when you you've made an error in your configuration, helping you avoid configuration mistakes! The configuration of Quartz can be broken down into two main parts: ```ts title="quartz.config.ts" const config: QuartzConfig = { configuration: { ... }, plugins: { ... }, } ``` ## General Configuration 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. - `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. - `enablePopovers`: whether to enable [[popover previews]] on your site. - `analytics`: what to use for analytics on your site. Values can be - `null`: don't use analytics; - `{ provider: 'google', tagId: '' }`: use Google Analytics; - `{ provider: 'plausible' }` (managed) or `{ provider: 'plausible', host: 'https://' }` (self-hosted, make sure to include the `https://` protocol prefix): use [Plausible](https://plausible.io/); - `{ provider: 'umami', host: '', websiteId: '' }`: use [Umami](https://umami.is/); - `{ provider: 'goatcounter', websiteId: 'my-goatcounter-id' }` (managed) or `{ provider: 'goatcounter', websiteId: 'my-goatcounter-id', host: 'my-goatcounter-domain.com', scriptSrc: 'https://my-url.to/counter.js' }` (self-hosted) use [GoatCounter](https://goatcounter.com); - `{ provider: 'posthog', apiKey: '', host: '' }`: use [Posthog](https://posthog.com/); - `{ provider: 'tinylytics', siteId: '' }`: use [Tinylytics](https://tinylytics.app/); - `{ provider: 'cabin' }` or `{ provider: 'cabin', host: 'https://cabin.example.com' }` (custom domain): use [Cabin](https://withcabin.com); - `{provider: 'clarity', projectId: ') 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. - `theme`: configure how the site looks. - `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. - `title`: font for the title of the site (optional, same as `header` by default) - `header`: font to use for headers - `code`: font for inline and block quotes - `body`: font for everything - `colors`: controls the theming of the site. - `light`: page background - `lightgray`: borders - `gray`: graph links, heavier borders - `darkgray`: body text - `dark`: header text and icons - `secondary`: link colour, current [[graph view|graph]] node - `tertiary`: hover states and visited [[graph view|graph]] nodes - `highlight`: internal link background, highlighted text, [[syntax highlighting|highlighted lines of code]] - `textHighlight`: markdown highlighted text background ## Plugins You can think of Quartz plugins as a series of transformations over content. ![[quartz transform pipeline.png]] ```ts title="quartz.config.ts" plugins: { transformers: [...], filters: [...], emitters: [...], } ``` - [[tags/plugin/transformer|Transformers]] **map** over content (e.g. parsing frontmatter, generating a description) - [[tags/plugin/filter|Filters]] **filter** content (e.g. filtering out drafts) - [[tags/plugin/emitter|Emitters]] **reduce** over content (e.g. creating an RSS feed or pages that list all files with a specific tag) You can customize the behaviour of Quartz by adding, removing and reordering plugins in the `transformers`, `filters` and `emitters` fields. > [!note] > Each node is modified by every transformer _in order_. Some transformers are position sensitive, so you may need to pay particular attention to whether they need to come before or after certain other plugins. You should take care to add the plugin to the right entry corresponding to its plugin type. For example, to add the [[ExplicitPublish]] plugin (a [[tags/plugin/filter|Filter]]), you would add the following line: ```ts title="quartz.config.ts" filters: [ ... Plugin.ExplicitPublish(), ... ], ``` To remove a plugin, you should remove all occurrences of it in the `quartz.config.ts`. To customize plugins further, some plugins may also have their own configuration settings that you can pass in. If you do not pass in a configuration, the plugin will use its default settings. For example, the [[plugins/Latex|Latex]] plugin allows you to pass in a field specifying the `renderEngine` to choose between Katex and MathJax. ```ts title="quartz.config.ts" transformers: [ Plugin.FrontMatter(), // use default options Plugin.Latex({ renderEngine: "katex" }), // set some custom options ] ``` 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]]. 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, }, ... } ``` ================================================ FILE: docs/features/Citations.md ================================================ --- 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. ================================================ FILE: docs/features/Docker Support.md ================================================ Quartz comes shipped with a Docker image that will allow you to preview your Quartz locally without installing Node. You can run the below one-liner to run Quartz in Docker. ```sh docker run --rm -itp 8080:8080 -p 3001:3001 -v ./content:/usr/src/app/content $(docker build -q .) ``` > [!warning] Not to be used for production > Serve mode is intended for local previews only. > For production workloads, see the page on [[hosting]]. ================================================ FILE: docs/features/Latex.md ================================================ --- title: LaTeX tags: - feature/transformer --- Quartz uses [Katex](https://katex.org/) by default to typeset both inline and block math expressions at build time. ## Syntax ### Block Math Block math can be rendered by delimiting math expression with `$$`. ``` $$ f(x) = \int_{-\infty}^\infty f\hat(\xi),e^{2 \pi i \xi x} \,d\xi $$ ``` $$ f(x) = \int_{-\infty}^\infty f\hat(\xi),e^{2 \pi i \xi x} \,d\xi $$ $$ \begin{aligned} a &= b + c \\ &= e + f \\ \end{aligned} $$ $$ \begin{bmatrix} 1 & 2 & 3 \\ a & b & c \end{bmatrix} $$ $$ \begin{array}{rll} E \psi &= H\psi & \text{Expanding the Hamiltonian Operator} \\ &= -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2} \psi + \frac{1}{2}m\omega x^2 \psi & \text{Using the ansatz $\psi(x) = e^{-kx^2}f(x)$, hoping to cancel the $x^2$ term} \\ &= -\frac{\hbar^2}{2m} [4k^2x^2f(x)+2(-2kx)f'(x) + f''(x)]e^{-kx^2} + \frac{1}{2}m\omega x^2 f(x)e^{-kx^2} &\text{Removing the $e^{-kx^2}$ term from both sides} \\ & \Downarrow \\ Ef(x) &= -\frac{\hbar^2}{2m} [4k^2x^2f(x)-4kxf'(x) + f''(x)] + \frac{1}{2}m\omega x^2 f(x) & \text{Choosing $k=\frac{im}{2}\sqrt{\frac{\omega}{\hbar}}$ to cancel the $x^2$ term, via $-\frac{\hbar^2}{2m}4k^2=\frac{1}{2}m \omega$} \\ &= -\frac{\hbar^2}{2m} [-4kxf'(x) + f''(x)] \\ \end{array} $$ > [!warn] > Due to limitations in the [underlying parsing library](https://github.com/remarkjs/remark-math), block math in Quartz requires the `$$` delimiters to be on newlines like above. ### Inline Math Similarly, inline math can be rendered by delimiting math expression with a single `$`. For example, `$e^{i\pi} = -1$` produces $e^{i\pi} = -1$ ### Escaping symbols There will be cases where you may have more than one `$` in a paragraph at once which may accidentally trigger MathJax/Katex. To get around this, you can escape the dollar sign by doing `\$` instead. For example: - Incorrect: `I have $1 and you have $2` produces I have $1 and you have $2 - Correct: `I have \$1 and you have \$2` produces I have \$1 and you have \$2 ### Using mhchem Add the following import to the top of `quartz/plugins/transformers/latex.ts` (before all the other imports): ```ts title="quartz/plugins/transformers/latex.ts" import "katex/contrib/mhchem" ``` ## Customization Latex parsing is a functionality of the [[plugins/Latex|Latex]] plugin. See the plugin page for customization options. ================================================ FILE: docs/features/Mermaid diagrams.md ================================================ --- title: "Mermaid Diagrams" tags: - feature/transformer --- Quartz supports Mermaid which allows you to add diagrams and charts to your notes. Mermaid supports a range of diagrams, such as [flow charts](https://mermaid.js.org/syntax/flowchart.html), [sequence diagrams](https://mermaid.js.org/syntax/sequenceDiagram.html), and [timelines](https://mermaid.js.org/syntax/timeline.html). This is enabled as a part of [[Obsidian compatibility]] and can be configured and enabled/disabled from that plugin. By default, Quartz will render Mermaid diagrams to match the site theme. > [!warning] > Wondering why Mermaid diagrams may not be showing up even if you have them enabled? You may need to reorder your plugins so that [[ObsidianFlavoredMarkdown]] is _after_ [[SyntaxHighlighting]]. ## Syntax To add a Mermaid diagram, create a mermaid code block. ```` ```mermaid sequenceDiagram Alice->>+John: Hello John, how are you? Alice->>+John: John, can you hear me? John-->>-Alice: Hi Alice, I can hear you! John-->>-Alice: I feel great! ``` ```` ```mermaid sequenceDiagram Alice->>+John: Hello John, how are you? Alice->>+John: John, can you hear me? John-->>-Alice: Hi Alice, I can hear you! John-->>-Alice: I feel great! ``` ================================================ FILE: docs/features/Obsidian compatibility.md ================================================ --- title: "Obsidian Compatibility" tags: - feature/transformer --- Quartz was originally designed as a tool to publish Obsidian vaults as websites. Even as the scope of Quartz has widened over time, it hasn't lost the ability to seamlessly interoperate with Obsidian. By default, Quartz ships with the [[ObsidianFlavoredMarkdown]] plugin, which is a transformer plugin that adds support for [Obsidian Flavored Markdown](https://help.obsidian.md/Editing+and+formatting/Obsidian+Flavored+Markdown). This includes support for features like [[wikilinks]] and [[Mermaid diagrams]]. It also ships with support for [frontmatter parsing](https://help.obsidian.md/Editing+and+formatting/Properties) with the same fields that Obsidian uses through the [[Frontmatter]] transformer plugin. Finally, Quartz also provides [[CrawlLinks]] plugin, which allows you to customize Quartz's link resolution behaviour to match Obsidian. ## Configuration This functionality is provided by the [[ObsidianFlavoredMarkdown]], [[Frontmatter]] and [[CrawlLinks]] plugins. See the plugin pages for customization options. ================================================ FILE: docs/features/OxHugo compatibility.md ================================================ --- title: "OxHugo Compatibility" tags: - feature/transformer --- [org-roam](https://www.orgroam.com/) is a plain-text personal knowledge management system for [emacs](https://en.wikipedia.org/wiki/Emacs). [ox-hugo](https://github.com/kaushalmodi/ox-hugo) is org exporter backend that exports `org-mode` files to [Hugo](https://gohugo.io/) compatible Markdown. Because the Markdown generated by ox-hugo is not pure Markdown but Hugo specific, we need to transform it to fit into Quartz. This is done by the [[OxHugoFlavoredMarkdown]] plugin. Even though this plugin was written with `ox-hugo` in mind, it should work for any Hugo specific Markdown. ```typescript title="quartz.config.ts" plugins: { transformers: [ Plugin.FrontMatter({ delims: "+++", language: "toml" }), // if toml frontmatter // ... Plugin.OxHugoFlavouredMarkdown(), Plugin.GitHubFlavoredMarkdown(), // ... ], }, ``` ## Usage Quartz by default doesn't understand `org-roam` files as they aren't Markdown. You're responsible for using an external tool like `ox-hugo` to export the `org-roam` files as Markdown content to Quartz and managing the static assets so that they're available in the final output. ## Configuration This functionality is provided by the [[OxHugoFlavoredMarkdown]] plugin. See the plugin page for customization options. ================================================ FILE: docs/features/RSS Feed.md ================================================ 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 This functionality is provided by the [[ContentIndex]] plugin. See the plugin page for customization options. ================================================ FILE: docs/features/Roam Research compatibility.md ================================================ --- 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. ================================================ FILE: docs/features/SPA Routing.md ================================================ Single-page-app style rendering. This prevents flashes of unstyled content and improves the smoothness of Quartz. Under the hood, this is done by hijacking page navigations and instead fetching the HTML via a `GET` request and then diffing and selectively replacing parts of the page using [micromorph](https://github.com/natemoo-re/micromorph). This allows us to change the content of the page without fully refreshing the page, reducing the amount of content that the browser needs to load. ## Configuration - Disable SPA Routing: set the `enableSPA` field of the [[configuration]] in `quartz.config.ts` to be `false`. ================================================ FILE: docs/features/backlinks.md ================================================ --- title: Backlinks tags: - component --- A backlink for a note is a link from another note to that note. Links in the backlink pane also feature rich [[popover previews]] if you have that feature enabled. ## Customization - 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` - Style: `quartz/components/styles/backlinks.scss` - Script: `quartz/components/scripts/search.inline.ts` ================================================ FILE: docs/features/breadcrumbs.md ================================================ --- title: "Breadcrumbs" tags: - component --- Breadcrumbs provide a way to navigate a hierarchy of pages within your site using a list of its parent folders. By default, the element at the very top of your page is the breadcrumb navigation bar (can also be seen at the top on this page!). ## Customization Most configuration can be done by passing in options to `Component.Breadcrumbs()`. For example, here's what the default configuration looks like: ```typescript title="quartz.layout.ts" Component.Breadcrumbs({ spacerSymbol: "❯", // symbol between crumbs rootName: "Home", // name of first/root element resolveFrontmatterTitle: true, // whether to resolve folder names through frontmatter titles showCurrentPage: true, // whether to display the current page in the breadcrumbs }) ``` When passing in your own options, you can omit any or all of these fields if you'd like to keep the default value for that field. You can also adjust where the breadcrumbs will be displayed by adjusting the [[layout]] (moving `Component.Breadcrumbs()` up or down) Want to customize it even more? - Removing breadcrumbs: delete all usages of `Component.Breadcrumbs()` from `quartz.layout.ts`. - Component: `quartz/components/Breadcrumbs.tsx` - Style: `quartz/components/styles/breadcrumbs.scss` - Script: inline at `quartz/components/Breadcrumbs.tsx` ================================================ FILE: docs/features/callouts.md ================================================ --- title: Callouts tags: - feature/transformer --- Quartz supports the same Admonition-callout syntax as Obsidian. This includes - 12 Distinct callout types (each with several aliases) - Collapsable callouts ``` > [!info] Title > This is a callout! ``` See [documentation on supported types and syntax here](https://help.obsidian.md/Editing+and+formatting/Callouts). > [!warning] > Wondering why callouts may not be showing up even if you have them enabled? You may need to reorder your plugins so that [[ObsidianFlavoredMarkdown]] is _after_ [[SyntaxHighlighting]]. ## Customization The callouts are a functionality of the [[ObsidianFlavoredMarkdown]] plugin. See the plugin page for how to enable or disable them. You can edit the icons by customizing `quartz/styles/callouts.scss`. ### Add custom callouts By default, custom callouts are handled by applying the `note` style. To make fancy ones, you have to add these lines to `custom.scss`. ```scss title="quartz/styles/custom.scss" .callout { &[data-callout="custom"] { --color: #customcolor; --border: #custombordercolor; --bg: #custombg; --callout-icon: url("data:image/svg+xml; utf8, "); //SVG icon code } } ``` > [!warning] > Don't forget to ensure that the SVG is URL encoded before putting it in the CSS. You can use tools like [this one](https://yoksel.github.io/url-encoder/) to help you do that. ## Showcase > [!info] > Default title > [!question]+ Can callouts be _nested_? > > > [!todo]- Yes!, they can. And collapsed! > > > > > [!example] You can even use multiple layers of nesting. > [!note] > Aliases: "note" > [!abstract] > Aliases: "abstract", "summary", "tldr" > [!info] > Aliases: "info" > [!todo] > Aliases: "todo" > [!tip] > Aliases: "tip", "hint", "important" > [!success] > Aliases: "success", "check", "done" > [!question] > Aliases: "question", "help", "faq" > [!warning] > Aliases: "warning", "attention", "caution" > [!failure] > Aliases: "failure", "missing", "fail" > [!danger] > Aliases: "danger", "error" > [!bug] > Aliases: "bug" > [!example] > Aliases: "example" > [!quote] > Aliases: "quote", "cite" ================================================ FILE: docs/features/comments.md ================================================ --- title: Comments tags: - component --- Quartz also has the ability to hook into various providers to enable readers to leave comments on your site. ![[giscus-example.png]] As of today, only [Giscus](https://giscus.app/) is supported out of the box but PRs to support other providers are welcome! ## Providers ### Giscus First, make sure that the [[setting up your GitHub repository|GitHub]] repository you are using for your Quartz meets the following requirements: 1. The **repository is [public](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/setting-repository-visibility#making-a-repository-public)**, otherwise visitors will not be able to view the discussion. 2. The **[giscus](https://github.com/apps/giscus) app is installed**, otherwise visitors will not be able to comment and react. 3. The **Discussions feature is turned on** by [enabling it for your repository](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/enabling-or-disabling-github-discussions-for-a-repository). Then, use the [Giscus site](https://giscus.app/#repository) to figure out what your `repoId` and `categoryId` should be. Make sure you select `Announcements` for the Discussion category. ![[giscus-repo.png]] ![[giscus-discussion.png]] After entering both your repository and selecting the discussion category, Giscus will compute some IDs that you'll need to provide back to Quartz. You won't need to manually add the script yourself as Quartz will handle that part for you but will need these values in the next step! ![[giscus-results.png]] Finally, in `quartz.layout.ts`, edit the `afterBody` field of `sharedPageComponents` to include the following options but with the values you got from above: ```ts title="quartz.layout.ts" afterBody: [ Component.Comments({ provider: 'giscus', options: { // from data-repo repo: 'jackyzha0/quartz', // from data-repo-id repoId: 'MDEwOlJlcG9zaXRvcnkzODcyMTMyMDg', // from data-category category: 'Announcements', // from data-category-id categoryId: 'DIC_kwDOFxRnmM4B-Xg6', // from data-lang lang: 'en' } }), ], ``` ### Customization Quartz also exposes a few of the other Giscus options as well and you can provide them the same way `repo`, `repoId`, `category`, and `categoryId` are provided. ```ts type Options = { provider: "giscus" options: { repo: `${string}/${string}` repoId: string category: 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 // defaults to 'url' mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname" // use strict title matching // defaults to true strict?: boolean // whether to enable reactions for the main post // defaults to true reactionsEnabled?: boolean // where to put the comment input box relative to the comments // defaults to 'bottom' inputPosition?: "top" | "bottom" // set your preference language here // defaults to 'en' lang?: string } } ``` #### 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 --- ``` ================================================ FILE: docs/features/darkmode.md ================================================ --- title: "Darkmode" tags: - component --- Quartz supports darkmode out of the box that respects the user's theme preference. Any future manual toggles of the darkmode switch will be saved in the browser's local storage so it can be persisted across future page loads. ## Customization - Removing darkmode: delete all usages of `Component.Darkmode()` from `quartz.layout.ts`. - Component: `quartz/components/Darkmode.tsx` - Style: `quartz/components/styles/darkmode.scss` - Script: `quartz/components/scripts/darkmode.inline.ts` You can also listen to the `themechange` event to perform any custom logic when the theme changes. ```js document.addEventListener("themechange", (e) => { console.log("Theme changed to " + e.detail.theme) // either "light" or "dark" // your logic here }) ``` ================================================ FILE: docs/features/explorer.md ================================================ --- title: "Explorer" tags: - component --- Quartz features an explorer that allows you to navigate all files and folders on your site. It supports nested folders and is highly customizable. By default, it shows all folders and files on your page. To display the explorer in a different spot, you can edit the [[layout]]. Display names for folders get determined by the `title` frontmatter field in `folder/index.md` (more detail in [[authoring content | Authoring Content]]). If this file does not exist or does not contain frontmatter, the local folder name will be used instead. > [!info] > The explorer uses local storage by default to save the state of your explorer. This is done to ensure a smooth experience when navigating to different pages. > > To clear/delete the explorer state from local storage, delete the `fileTree` entry (guide on how to delete a key from local storage in chromium based browsers can be found [here](https://docs.devolutions.net/kb/general-knowledge-base/clear-browser-local-storage/clear-chrome-local-storage/)). You can disable this by passing `useSavedState: false` as an argument. ## Customization Most configuration can be done by passing in options to `Component.Explorer()`. For example, here's what the default configuration looks like: ```typescript title="quartz.layout.ts" Component.Explorer({ title: "Explorer", // title of the explorer component 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") useSavedState: true, // whether to use local storage to save "state" (which folders are opened) of explorer // omitted but shown later sortFn: ..., filterFn: ..., mapFn: ..., // what order to apply functions in order: ["filter", "map", "sort"], }) ``` When passing in your own options, you can omit any or all of these fields if you'd like to keep the default value for that field. Want to customize it even more? - Removing explorer: remove `Component.Explorer()` from `quartz.layout.ts` - (optional): After removing the explorer component, you can move the [[table of contents | Table of Contents]] component back to the `left` part of the layout - Changing `sort`, `filter` and `map` behavior: explained in [[#Advanced customization]] - Component: `quartz/components/Explorer.tsx` - Style: `quartz/components/styles/explorer.scss` - Script: `quartz/components/scripts/explorer.inline.ts` ## Advanced customization 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 `FileTrieNode` class, which has the following properties: ```ts title="quartz/components/Explorer.tsx" class FileTrieNode { isFolder: boolean children: Array data: ContentDetails | null } ``` ```ts title="quartz/plugins/emitters/contentIndex.tsx" export type ContentDetails = { slug: FullSlug title: string links: SimpleSlug[] tags: string[] content: string } ``` Every function you can pass is optional. By default, only a `sort` function will be used: ```ts title="Default sort function" // Sort order: folders first, then files. Sort folders and files alphabetically Component.Explorer({ sortFn: (a, b) => { if ((!a.isFolder && !b.isFolder) || (a.isFolder && b.isFolder)) { return a.displayName.localeCompare(b.displayName, undefined, { numeric: true, sensitivity: "base", }) } if (!a.isFolder && b.isFolder) { return 1 } else { return -1 } }, }) ``` --- You can pass your own functions for `sortFn`, `filterFn` and `mapFn`. All functions will be executed in the order provided by the `order` option (see [[#Customization]]). These functions behave similarly to their `Array.prototype` counterpart, except they modify the entire `FileNode` tree in place instead of returning a new one. For more information on how to use `sort`, `filter` and `map`, you can check [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort), [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) and [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map). Type definitions look like this: ```ts type SortFn = (a: FileTrieNode, b: FileTrieNode) => number type FilterFn = (node: FileTrieNode) => boolean type MapFn = (node: FileTrieNode) => void ``` ## Basic examples These examples show the basic usage of `sort`, `map` and `filter`. ### Use `sort` to put files first Using this example, the explorer will alphabetically sort everything. ```ts title="quartz.layout.ts" Component.Explorer({ sortFn: (a, b) => { return a.displayName.localeCompare(b.displayName) }, }) ``` ### Change display names (`map`) Using this example, the display names of all `FileNodes` (folders + files) will be converted to full upper case. ```ts title="quartz.layout.ts" Component.Explorer({ mapFn: (node) => { node.displayName = node.displayName.toUpperCase() return node }, }) ``` ### Remove list of elements (`filter`) 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" Component.Explorer({ filterFn: (node) => { // set containing names of everything you want to filter out const omit = new Set(["authoring content", "tags", "advanced"]) // 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()) }, }) ``` ### Remove files by tag You can access the tags of a file by `node.data.tags`. ```ts title="quartz.layout.ts" Component.Explorer({ filterFn: (node) => { // exclude files with the tag "explorerexclude" return node.data?.tags?.includes("explorerexclude") !== true }, }) ``` ### Show every element in explorer 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" Component.Explorer({ filterFn: undefined, // apply no filter function, every file and folder will visible }) ``` ## Advanced examples > [!tip] > When writing more complicated functions, the `layout` file can start to look very cramped. > You can fix this by defining your sort functions outside of the component > and passing it in. > > ```ts title="quartz.layout.ts" > import { Options } from "./quartz/components/Explorer" > > export const mapFn: Options["mapFn"] = (node) => { > // implement your function here > } > export const filterFn: Options["filterFn"] = (node) => { > // implement your function here > } > export const sortFn: Options["sortFn"] = (a, b) => { > // implement your function here > } > > Component.Explorer({ > // ... your other options > mapFn, > filterFn, > sortFn, > }) > ``` ### Add emoji prefix To add emoji prefixes (📁 for folders, 📄 for files), you could use a map function like this: ```ts title="quartz.layout.ts" Component.Explorer({ mapFn: (node) => { if (node.isFolder) { node.displayName = "📁 " + node.displayName } else { node.displayName = "📄 " + node.displayName } }, }) ``` ================================================ FILE: docs/features/folder and tag listings.md ================================================ --- title: Folder and Tag Listings tags: - feature/emitter --- Quartz emits listing pages for any folders and tags you have. ## Folder Listings Quartz will generate an index page for all the pages under that folder. This includes any content that is multiple levels deep. Additionally, Quartz will also generate pages for subfolders. Say you have a note in a nested folder `content/abc/def/note.md`. Then Quartz would generate a page for all the notes under `abc` _and_ a page for all the notes under `abc/def`. You can link to the folder listing by referencing its name, plus a trailing slash, like this: `[[advanced/]]` (results in [[advanced/]]). By default, Quartz will title the page `Folder: ` and no description. You can override this by creating an `index.md` file in the folder with the `title` [[authoring content#Syntax|frontmatter]] field. Any content you write in this file will also be used in the folder description. For example, for the folder `content/posts`, you can add another file `content/posts/index.md` to add a specific description for it. ## Tag Listings Quartz will also create an index page for each unique tag in your vault and render a list of all notes with that tag. Quartz also supports tag hierarchies as well (e.g. `plugin/emitter`) and will also render a separate tag page for each level of the tag hierarchy. It will also create a default global tag index page at `/tags` that displays a list of all the tags in your Quartz. You can link to the tag listing by referencing its name with a `tag/` prefix, like this: `[[tags/plugin]]` (results in [[tags/plugin]]). As with folder listings, you can also provide a description and title for a tag page by creating a file for each tag. For example, if you wanted to create a custom description for the #component tag, you would create a file at `content/tags/component.md` with a title and description. ## Customization Quartz allows you to define a custom sort ordering for content on both page types. The folder listings are a functionality of the [[FolderPage]] plugin, the tag listings of the [[TagPage]] plugin. See the plugin pages for customization options. ================================================ FILE: docs/features/full-text search.md ================================================ --- title: Full-text Search tags: - component --- Full-text search in Quartz is powered by [Flexsearch](https://github.com/nextapps-de/flexsearch). It's fast enough to return search results in under 10ms for Quartzs as large as half a million words. It can be opened by either clicking on the search bar or pressing `⌘`/`ctrl` + `K`. The top 5 search results are shown on each query. Matching subterms are highlighted and the most relevant 30 words are excerpted. Clicking on a search result will navigate to that page. To search content by tags, you can either press `⌘`/`ctrl` + `shift` + `K` or start your query with `#` (e.g. `#components`). This component is also keyboard accessible: Tab and Shift+Tab will cycle forward and backward through search results and Enter will navigate to the highlighted result (first result by default). You are also able to navigate search results using `ArrowUp` and `ArrowDown`. > [!info] > Search requires the `ContentIndex` emitter plugin to be present in the [[configuration]]. ### Indexing Behaviour By default, it indexes every page on the site with **Markdown syntax removed**. This means link URLs for instance are not indexed. It properly tokenizes Chinese, Korean, and Japenese characters and constructs separate indexes for the title, content and tags, weighing title matches above content matches. ## Customization - Removing search: delete all usages of `Component.Search()` from `quartz.layout.ts`. - Component: `quartz/components/Search.tsx` - Style: `quartz/components/styles/search.scss` - Script: `quartz/components/scripts/search.inline.ts` - You can edit `contextWindowWords`, `numSearchResults` or `numTagResults` to suit your needs ================================================ FILE: docs/features/graph view.md ================================================ --- title: "Graph View" tags: - component --- Quartz features a graph-view that can show both a local graph view and a global graph view. - The local graph view shows files that either link to the current file or are linked from the current file. In other words, it shows all notes that are _at most_ one hop away. - The global graph view can be toggled by clicking the graph icon on the top-right of the local graph view. It shows _all_ the notes in your graph and how they connect to each other. By default, the node radius is proportional to the total number of incoming and outgoing internal links from that file. Additionally, similar to how browsers highlight visited links a different colour, the graph view will also show nodes that you have visited in a different colour. > [!info] > Graph View requires the `ContentIndex` emitter plugin to be present in the [[configuration]]. ## Customization Most configuration can be done by passing in options to `Component.Graph()`. For example, here's what the default configuration looks like: ```typescript title="quartz.layout.ts" Component.Graph({ localGraph: { drag: true, // whether to allow panning the view around zoom: true, // whether to allow zooming in and out depth: 1, // how many hops of notes to display scale: 1.1, // default view scale repelForce: 0.5, // how much nodes should repel each other centerForce: 0.3, // how much force to use when trying to center the nodes linkDistance: 30, // how long should the links be by default? fontSize: 0.6, // what size should the node labels be? opacityScale: 1, // how quickly do we fade out the labels when zooming out? removeTags: [], // what tags to remove from the graph showTags: true, // whether to show tags in the graph enableRadial: false, // whether to constrain the graph, similar to Obsidian }, globalGraph: { drag: true, zoom: true, depth: -1, scale: 0.9, repelForce: 0.5, centerForce: 0.3, linkDistance: 30, fontSize: 0.6, opacityScale: 1, removeTags: [], // what tags to remove from the graph showTags: true, // whether to show tags in the graph enableRadial: true, // whether to constrain the graph, similar to Obsidian }, }) ``` When passing in your own options, you can omit any or all of these fields if you'd like to keep the default value for that field. Want to customize it even more? - Removing graph view: delete all usages of `Component.Graph()` from `quartz.layout.ts`. - Component: `quartz/components/Graph.tsx` - Style: `quartz/components/styles/graph.scss` - Script: `quartz/components/scripts/graph.inline.ts` ================================================ FILE: docs/features/i18n.md ================================================ --- title: Internationalization --- Internationalization allows users to translate text in the Quartz interface into various supported languages without needing to make extensive code changes. This can be changed via the `locale` [[configuration]] field in `quartz.config.ts`. The locale field generally follows a certain format: `{language}-{REGION}` - `{language}` is usually a [2-letter lowercase language code](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes). - `{REGION}` is usually a [2-letter uppercase region code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) > [!tip] Interested in contributing? > We [gladly welcome translation PRs](https://github.com/jackyzha0/quartz/tree/v4/quartz/i18n/locales)! To contribute a translation, do the following things: > > 1. In the `quartz/i18n/locales` folder, copy the `en-US.ts` file. > 2. Rename it to `{language}-{REGION}.ts` so it matches a locale of the format shown above. > 3. Fill in the translations! > 4. Add the entry under `TRANSLATIONS` in `quartz/i18n/index.ts`. ================================================ FILE: docs/features/index.md ================================================ --- title: Feature List --- ================================================ FILE: docs/features/popover previews.md ================================================ --- title: Popover Previews --- Like Wikipedia, when you hover over a link in Quartz, there is a popup of a page preview that you can scroll to see the entire content. Links to headers will also scroll the popup to show that specific header in view. By default, Quartz only fetches previews for pages inside your vault due to [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). It does this by selecting all HTML elements with the `popover-hint` class. For most pages, this includes the page title, page metadata like words and time to read, tags, and the actual page content. When [[creating components|creating your own components]], you can include this `popover-hint` class to also include it in the popover. Similar to Obsidian, [[quartz-layout-desktop.png|images referenced using wikilinks]] can also be viewed as popups. ## Configuration - Remove popovers: set the `enablePopovers` field in `quartz.config.ts` to be `false`. - Style: `quartz/components/styles/popover.scss` - Script: `quartz/components/scripts/popover.inline.ts` ================================================ FILE: docs/features/private pages.md ================================================ --- title: Private Pages tags: - feature/filter --- There may be some notes you want to avoid publishing as a website. Quartz supports this through two mechanisms which can be used in conjunction: ## Filter Plugins [[making plugins#Filters|Filter plugins]] are plugins that filter out content based off of certain criteria. By default, Quartz uses the [[RemoveDrafts]] plugin which filters out any note that has `draft: true` in the frontmatter. If you'd like to only publish a select number of notes, you can instead use [[ExplicitPublish]] which will filter out all notes except for any that have `publish: true` in the frontmatter. > [!warning] > Regardless of the filter plugin used, **all non-markdown files will be emitted and available publically in the final build.** This includes files such as images, voice recordings, PDFs, etc. ## `ignorePatterns` This is a field in `quartz.config.ts` under the main [[configuration]] which allows you to specify a list of patterns to effectively exclude from parsing all together. Any valid [fast-glob](https://github.com/mrmlnc/fast-glob#pattern-syntax) pattern works here. > [!note] > Bash's glob syntax is slightly different from fast-glob's and using bash's syntax may lead to unexpected results. Common examples include: - `some/folder`: exclude the entire of `some/folder` - `*.md`: exclude all files with a `.md` extension - `!(*.md)` exclude all files that _don't_ have a `.md` extension. Note that negations _must_ parenthesize the rest of the pattern! - `**/private`: exclude any files or folders named `private` at any level of nesting > [!warning] > Marking something as private via either a plugin or through the `ignorePatterns` pattern will only prevent a page from being included in the final built site. If your GitHub repository is public, also be sure to include an ignore for those in the `.gitignore` of your Quartz. See the `git` [documentation](https://git-scm.com/docs/gitignore#_pattern_format) for more information. ================================================ FILE: docs/features/reader mode.md ================================================ --- 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); } } ``` ================================================ FILE: docs/features/recent notes.md ================================================ --- title: Recent Notes tags: component --- Quartz can generate a list of recent notes based on some filtering and sorting criteria. Though this component isn't included in any [[layout]] by default, you can add it by using `Component.RecentNotes` in `quartz.layout.ts`. ## Customization - Changing the title from "Recent notes": pass in an additional parameter to `Component.RecentNotes({ title: "Recent writing" })` - Changing the number of recent notes: pass in an additional parameter to `Component.RecentNotes({ limit: 5 })` - Display the note's tags (defaults to true): `Component.RecentNotes({ showTags: false })` - Show a 'see more' link: pass in an additional parameter to `Component.RecentNotes({ linkToMore: "tags/components" })`. This field should be a full slug to a page that exists. - Customize filtering: pass in an additional parameter to `Component.RecentNotes({ filter: someFilterFunction })`. The filter function should be a function that has the signature `(f: QuartzPluginData) => boolean`. - Customize sorting: pass in an additional parameter to `Component.RecentNotes({ sort: someSortFunction })`. By default, Quartz will sort by date and then tie break lexographically. The sort function should be a function that has the signature `(f1: QuartzPluginData, f2: QuartzPluginData) => number`. See `byDateAndAlphabetical` in `quartz/components/PageList.tsx` for an example. - Component: `quartz/components/RecentNotes.tsx` - Style: `quartz/components/styles/recentNotes.scss` ================================================ FILE: docs/features/social images.md ================================================ --- 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. ================================================ FILE: docs/features/syntax highlighting.md ================================================ --- title: Syntax Highlighting tags: - feature/transformer --- Syntax highlighting in Quartz is completely done at build-time. This means that Quartz only ships pre-calculated CSS to highlight the right words so there is no heavy client-side bundle that does the syntax highlighting. And, unlike some client-side highlighters, it has a full TextMate parser grammar instead of using Regexes, allowing for highly accurate code highlighting. In short, it generates HTML that looks exactly like your code in an editor like VS Code. Under the hood, it's powered by [Rehype Pretty Code](https://rehype-pretty-code.netlify.app/) which uses [Shiki](https://github.com/shikijs/shiki). > [!warning] > Syntax highlighting does have an impact on build speed if you have a lot of code snippets in your notes. ## Formatting Text inside `backticks` on a line will be formatted like code. ```` ```ts export function trimPathSuffix(fp: string): string { fp = clientSideSlug(fp) let [cleanPath, anchor] = fp.split("#", 2) anchor = anchor === undefined ? "" : "#" + anchor return cleanPath + anchor } ``` ```` ```ts export function trimPathSuffix(fp: string): string { fp = clientSideSlug(fp) let [cleanPath, anchor] = fp.split("#", 2) anchor = anchor === undefined ? "" : "#" + anchor return cleanPath + anchor } ``` ### Titles Add a file title to your code block, with text inside double quotes (`""`): ```` ```js title="..." ``` ```` ```ts title="quartz/path.ts" export function trimPathSuffix(fp: string): string { fp = clientSideSlug(fp) let [cleanPath, anchor] = fp.split("#", 2) anchor = anchor === undefined ? "" : "#" + anchor return cleanPath + anchor } ``` ### Line highlighting Place a numeric range inside `{}`. ```` ```js {1-3,4} ``` ```` ```ts {2-3,6} export function trimPathSuffix(fp: string): string { fp = clientSideSlug(fp) let [cleanPath, anchor] = fp.split("#", 2) anchor = anchor === undefined ? "" : "#" + anchor return cleanPath + anchor } ``` ### Word highlighting A series of characters, like a literal regex. ```` ```js /useState/ const [age, setAge] = useState(50); const [name, setName] = useState('Taylor'); ``` ```` ```js /useState/ const [age, setAge] = useState(50) const [name, setName] = useState("Taylor") ``` ### Inline Highlighting Append {:lang} to the end of inline code to highlight it like a regular code block. ``` This is an array `[1, 2, 3]{:js}` of numbers 1 through 3. ``` This is an array `[1, 2, 3]{:js}` of numbers 1 through 3. ### Line numbers Syntax highlighting has line numbers configured automatically. If you want to start line numbers at a specific number, use `showLineNumbers{number}`: ```` ```js showLineNumbers{number} ``` ```` ```ts showLineNumbers{20} export function trimPathSuffix(fp: string): string { fp = clientSideSlug(fp) let [cleanPath, anchor] = fp.split("#", 2) anchor = anchor === undefined ? "" : "#" + anchor return cleanPath + anchor } ``` ### Escaping code blocks You can format a codeblock inside of a codeblock by wrapping it with another level of backtick fences that has one more backtick than the previous fence. ````` ```` ```js /useState/ const [age, setAge] = useState(50); const [name, setName] = useState('Taylor'); ``` ```` ````` ## Customization Syntax highlighting is a functionality of the [[SyntaxHighlighting]] plugin. See the plugin page for customization options. ================================================ FILE: docs/features/table of contents.md ================================================ --- title: "Table of Contents" tags: - component - feature/transformer --- Quartz can automatically generate a table of contents (TOC) from a list of headings on each page. It will also show you your current scrolling position on the page by highlighting headings you've scrolled through with a different color. You can hide the TOC on a page by adding `enableToc: false` to the frontmatter for that page. By default, the TOC shows all headings from H1 (`# Title`) to H3 (`### Title`) and is only displayed if there is more than one heading on the page. ## Customization The table of contents is a functionality of the [[TableOfContents]] plugin. See the plugin page for more customization options. It also needs the `TableOfContents` component, which is displayed in the right sidebar by default. You can change this by customizing the [[layout]]. The TOC component can be configured with the `layout` parameter, which can either be `modern` (default) or `legacy`. ================================================ FILE: docs/features/upcoming features.md ================================================ --- draft: true --- ## misc backlog - static dead link detection - cursor chat extension - sidenotes? https://github.com/capnfabs/paperesque - direct match in search using double quotes - https://help.obsidian.md/Advanced+topics/Using+Obsidian+URI - Canvas ================================================ FILE: docs/features/wikilinks.md ================================================ --- title: Wikilinks --- Wikilinks were pioneered by earlier internet wikis to make it easier to write links across pages without needing to write Markdown or HTML links each time. Quartz supports Wikilinks by default and these links are resolved by Quartz using the [[CrawlLinks]] plugin. See the [Obsidian Help page on Internal Links](https://help.obsidian.md/Linking+notes+and+files/Internal+links) for more information on Wikilink syntax. This is enabled as a part of [[Obsidian compatibility]] and can be configured and enabled/disabled from that plugin. ## Syntax - `[[Path to file]]`: produces a link to `Path to file.md` (or `Path-to-file.md`) with the text `Path to file` - `[[Path to file | Here's the title override]]`: produces a link to `Path to file.md` with the text `Here's the title override` - `[[Path to file#Anchor]]`: produces a link to the anchor `Anchor` in the file `Path to file.md` - `[[Path to file#^block-ref]]`: produces a link to the specific block `block-ref` in the file `Path to file.md` ### Embeds - `![[Path to image]]`: embeds an image into the page - `![[Path to image|100x145]]`: embeds an image into the page with dimensions 100px by 145px - `![[Path to file]]`: transclude an entire page - `![[Path to file#Anchor]]`: transclude everything under the header `Anchor` - `![[Path to file#^b15695]]`: transclude block with ID `^b15695` ================================================ FILE: docs/hosting.md ================================================ --- title: Hosting --- Quartz effectively turns your Markdown files and other resources into a bundle of HTML, JS, and CSS files (a website!). However, if you'd like to publish your site to the world, you need a way to host it online. This guide will detail how to deploy with common hosting providers but any service that allows you to deploy static HTML should work as well. > [!warning] > The rest of this guide assumes that you've already created your own GitHub repository for Quartz. If you haven't already, [[setting up your GitHub repository|make sure you do so]]. > [!hint] > Some Quartz features (like [[RSS Feed]] and sitemap generation) require `baseUrl` to be configured properly in your [[configuration]] to work properly. Make sure you set this before deploying! ## Cloudflare Pages 1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and select your account. 2. In Account Home, select **Compute (Workers)** > **Workers & Pages** > **Create application** > **Pages** > **Connect to Git**. 3. Select the new GitHub repository that you created and, in the **Set up builds and deployments** section, provide the following information: | Configuration option | Value | | ---------------------- | ------------------ | | Production branch | `v4` | | Framework preset | `None` | | Build command | `npx quartz build` | | Build output directory | `public` | Press "Save and deploy" and Cloudflare should have a deployed version of your site in about a minute. Then, every time you sync your Quartz changes to GitHub, your site should be updated. To add a custom domain, check out [Cloudflare's documentation](https://developers.cloudflare.com/pages/platform/custom-domains/). > [!warning] > Cloudflare Pages performs a shallow clone by default, so if you rely on `git` for timestamps, it is recommended that you add `git fetch --unshallow &&` to the beginning of the build command (e.g., `git fetch --unshallow && npx quartz build`). ## GitHub Pages In your local Quartz, create a new file `quartz/.github/workflows/deploy.yml`. ```yaml title="quartz/.github/workflows/deploy.yml" name: Deploy Quartz site to GitHub Pages on: push: branches: - v4 permissions: contents: read pages: write id-token: write concurrency: group: "pages" cancel-in-progress: false jobs: build: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for git info - uses: actions/setup-node@v4 with: node-version: 22 - name: Install Dependencies run: npm ci - name: Build Quartz run: npx quartz build - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: public deploy: needs: build environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 ``` Then: 1. Head to "Settings" tab of your forked repository and in the sidebar, click "Pages". Under "Source", select "GitHub Actions". 2. Commit these changes by doing `npx quartz sync`. This should deploy your site to `.github.io/`. > [!hint] > If you get an error about not being allowed to deploy to `github-pages` due to environment protection rules, make sure you remove any existing GitHub pages environments. > > You can do this by going to your Settings page on your GitHub fork and going to the Environments tab and pressing the trash icon. The GitHub action will recreate the environment for you correctly the next time you sync your Quartz. > [!info] > Quartz generates files in the format of `file.html` instead of `file/index.html` which means the trailing slashes for _non-folder paths_ are dropped. As GitHub pages does not do this redirect, this may cause existing links to your site that use trailing slashes to break. If not breaking existing links is important to you (e.g. you are migrating from Quartz 3), consider using [[#Cloudflare Pages]]. ### Custom Domain Here's how to add a custom domain to your GitHub pages deployment. 1. Head to the "Settings" tab of your forked repository. 2. In the "Code and automation" section of the sidebar, click "Pages". 3. Under "Custom Domain", type your custom domain and click "Save". 4. This next step depends on whether you are using an apex domain (`example.com`) or a subdomain (`subdomain.example.com`). - If you are using an apex domain, navigate to your DNS provider and create an `A` record that points your apex domain to GitHub's name servers which have the following IP addresses: - `185.199.108.153` - `185.199.109.153` - `185.199.110.153` - `185.199.111.153` - If you are using a subdomain, navigate to your DNS provider and create a `CNAME` record that points your subdomain to the default domain for your site. For example, if you want to use the subdomain `quartz.example.com` for your user site, create a `CNAME` record that points `quartz.example.com` to `.github.io`. ![[dns records.png]]_The above shows a screenshot of Google Domains configured for both `jzhao.xyz` (an apex domain) and `quartz.jzhao.xyz` (a subdomain)._ See the [GitHub documentation](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#configuring-a-subdomain) for more detail about how to setup your own custom domain with GitHub Pages. > [!question] Why aren't my changes showing up? > There could be many different reasons why your changes aren't showing up but the most likely reason is that you forgot to push your changes to GitHub. > > Make sure you save your changes to Git and sync it to GitHub by doing `npx quartz sync`. This will also make sure to pull any updates you may have made from other devices so you have them locally. ## Vercel ### Fix URLs Before deploying to Vercel, a `vercel.json` file is required at the root of the project directory. It needs to contain the following configuration so that URLs don't require the `.html` extension: ```json title="vercel.json" { "cleanUrls": true } ``` ### Deploy to Vercel 1. Log in to the [Vercel Dashboard](https://vercel.com/dashboard) and click "Add New..." > Project 2. Import the Git repository containing your Quartz project. 3. Give the project a name (lowercase characters and hyphens only) 4. Check that these configuration options are set: | Configuration option | Value | | ----------------------------------------- | ------------------ | | Framework Preset | `Other` | | Root Directory | `./` | | Build and Output Settings > Build Command | `npx quartz build` | 5. Press Deploy. Once it's live, you'll have 2 `*.vercel.app` URLs to view the page. ### Custom Domain > [!note] > If there is something already hosted on the domain, these steps will not work without replacing the previous content. As a workaround, you could use Next.js rewrites or use the next section to create a subdomain. 1. Update the `baseUrl` in `quartz.config.js` if necessary. 2. Go to the [Domains - Dashboard](https://vercel.com/dashboard/domains) page in Vercel. 3. Connect the domain to Vercel 4. Press "Add" to connect a custom domain to Vercel. 5. Select your Quartz repository and press Continue. 6. Enter the domain you want to connect it to. 7. Follow the instructions to update your DNS records until you see "Valid Configuration" ### Use a Subdomain Using `docs.example.com` is an example of a subdomain. They're a simple way of connecting multiple deployments to one domain. 1. Update the `baseUrl` in `quartz.config.js` if necessary. 2. Ensure your domain has been added to the [Domains - Dashboard](https://vercel.com/dashboard/domains) page in Vercel. 3. Go to the [Vercel Dashboard](https://vercel.com/dashboard) and select your Quartz project. 4. Go to the Settings tab and then click Domains in the sidebar 5. Enter your subdomain into the field and press Add ## Netlify 1. Log in to the [Netlify dashboard](https://app.netlify.com/) and click "Add new site". 2. Select your Git provider and repository containing your Quartz project. 3. Under "Build command", enter `npx quartz build`. 4. Under "Publish directory", enter `public`. 5. Press Deploy. Once it's live, you'll have a `*.netlify.app` URL to view the page. 6. To add a custom domain, check "Domain management" in the left sidebar, just like with Vercel. ## GitLab Pages In your local Quartz, create a new file `.gitlab-ci.yml`. ```yaml title=".gitlab-ci.yml" stages: - build - deploy image: node:22 cache: # Cache modules in between jobs key: $CI_COMMIT_REF_SLUG paths: - .npm/ build: stage: build rules: - if: '$CI_COMMIT_REF_NAME == "v4"' before_script: - hash -r - npm ci --cache .npm --prefer-offline script: - npx quartz build artifacts: paths: - public tags: - gitlab-org-docker pages: stage: deploy rules: - if: '$CI_COMMIT_REF_NAME == "v4"' script: - echo "Deploying to GitLab Pages..." artifacts: paths: - public ``` When `.gitlab-ci.yaml` is committed, GitLab will build and deploy the website as a GitLab Page. You can find the url under `Deploy > Pages` in the sidebar. By default, the page is private and only visible when logged in to a GitLab account with access to the repository but can be opened in the settings under `Deploy` -> `Pages`. ## Self-Hosting Copy the `public` directory to your web server and configure it to serve the files. You can use any web server to host your site. Since Quartz generates links that do not include the `.html` extension, you need to let your web server know how to deal with it. ### Using Nginx Here's an example of how to do this with Nginx: ```nginx title="nginx.conf" server { listen 80; server_name example.com; root /path/to/quartz/public; index index.html; error_page 404 /404.html; location / { try_files $uri $uri.html $uri/ =404; } } ``` ### 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 Here's and example of how to do this with Caddy: ```caddy title="Caddyfile" example.com { root * /path/to/quartz/public try_files {path} {path}.html {path}/ =404 file_server encode gzip handle_errors { rewrite * /{err.status_code}.html file_server } } ``` ================================================ FILE: docs/index.md ================================================ --- title: Welcome to Quartz 4 --- Quartz is a fast, batteries-included static-site generator that transforms Markdown content into fully functional websites. Thousands of students, developers, and teachers are [[showcase|already using Quartz]] to publish personal notes, websites, and [digital gardens](https://jzhao.xyz/posts/networked-thought) to the web. ## 🪴 Get Started Quartz requires **at least [Node](https://nodejs.org/) v22** and `npm` v10.9.2 to function correctly. Ensure you have this installed on your machine before continuing. Then, in your terminal of choice, enter the following commands line by line: ```shell git clone https://github.com/jackyzha0/quartz.git cd quartz npm i npx quartz create ``` This will guide you through initializing your Quartz with content. Once you've done so, see how to: 1. [[authoring content|Writing content]] in Quartz 2. [[configuration|Configure]] Quartz's behaviour 3. Change Quartz's [[layout]] 4. [[build|Build and preview]] Quartz 5. Sync your changes with [[setting up your GitHub repository|GitHub]] 6. [[hosting|Host]] Quartz online If you prefer instructions in a video format you can try following Nicole van der Hoeven's [video guide on how to set up Quartz!](https://www.youtube.com/watch?v=6s6DT1yN4dw&t=227s) ## 🔧 Features - [[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 on configuration edits and incremental rebuilds for content edits - Simple JSX layouts and [[creating components|page components]] - [[SPA Routing|Ridiculously fast page loads]] and tiny bundle sizes - 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. ### 🚧 Troubleshooting + Updating Having trouble with Quartz? Try searching for your issue using the search feature. If you haven't already, [[upgrading|upgrade]] to the newest version of Quartz to see if this fixes your issue. If you're still having trouble, feel free to [submit an issue](https://github.com/jackyzha0/quartz/issues) if you feel you found a bug or ask for help in our [Discord Community](https://discord.gg/cRFFHYye7t). ================================================ FILE: docs/layout-components.md ================================================ --- 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", }) ``` > [!note] Overriding behavior > Components inside `Flex` get an additional CSS class `flex-component` that add the `display: flex` property. If you want to override this behavior, you can add a `display` property to the component's CSS class in your custom CSS file. > > ```scss > .flex-component { > display: block; // or any other display type > } > ``` ## `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. ================================================ FILE: docs/layout.md ================================================ --- title: Layout --- Certain emitters may also output [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) files. To enable easy customization, these emitters allow you to fully rearrange the layout of the page. The default page layouts can be found in `quartz.layout.ts`. Each page is composed of multiple different sections which contain `QuartzComponents`. The following code snippet lists all of the valid sections that you can add components to: ```typescript title="quartz/cfg.ts" export interface FullPageLayout { head: QuartzComponent // single component header: QuartzComponent[] // laid out horizontally beforeBody: QuartzComponent[] // laid out vertically pageBody: QuartzComponent // single component afterBody: QuartzComponent[] // laid out vertically left: QuartzComponent[] // vertical on desktop and tablet, horizontal on mobile right: QuartzComponent[] // vertical on desktop, horizontal on tablet and mobile footer: QuartzComponent // single component } ``` These correspond to following parts of the page: | 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] > There are two additional layout fields that are _not_ shown in the above diagram. > > 1. `head` is a single component that renders the `` [tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head) in the HTML. This doesn't appear visually on the page and is only is responsible for metadata about the document like the tab title, scripts, and styles. > 2. `header` is a set of components that are laid out horizontally and appears _before_ the `beforeBody` section. This enables you to replicate the old Quartz 3 header bar where the title, search bar, and dark mode toggle. By default, Quartz 4 doesn't place any components in the `header`. 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. 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 Most meaningful style changes like colour scheme and font can be done simply through the [[configuration#General Configuration|general configuration]] options. However, if you'd like to make more involved style changes, you can do this by writing your own styles. Quartz 4, like Quartz 3, uses [Sass](https://sass-lang.com/guide/) for styling. You can see the base style sheet in `quartz/styles/base.scss` and write your own in `quartz/styles/custom.scss`. > [!note] > Some components may provide their own styling as well! For example, `quartz/components/Darkmode.tsx` imports styles from `quartz/components/styles/darkmode.scss`. If you'd like to customize styling for a specific component, double check the component definition to see how its styles are defined. ================================================ FILE: docs/migrating from Quartz 3.md ================================================ --- title: "Migrating from Quartz 3" --- As you already have Quartz locally, you don't need to fork or clone it again. Simply just checkout the alpha branch, install the dependencies, and import your old vault. ```bash git fetch git checkout v4 git pull upstream v4 npm i npx quartz create ``` If you get an error like `fatal: 'upstream' does not appear to be a git repository`, make sure you add `upstream` as a remote origin: ```shell git remote add upstream https://github.com/jackyzha0/quartz.git ``` When running `npx quartz create`, you will be prompted as to how to initialize your content folder. Here, you can choose to import or link your previous content folder and Quartz should work just as you expect it to. > [!note] > If the existing content folder you'd like to use is at the _same_ path on a different branch, clone the repo again somewhere at a _different_ path in order to use it. ## Key changes 1. **Removing Hugo and `hugo-obsidian`**: Hugo worked well for earlier versions of Quartz but it also made it hard for people outside of the Golang and Hugo communities to fully understand what Quartz was doing under the hood and be able to properly customize it to their needs. Quartz 4 now uses a Node-based static-site generation process which should lead to a much more helpful error messages and an overall smoother user experience. 2. **Full-hot reload**: The many rough edges of how `hugo-obsidian` integrated with Hugo meant that watch mode didn't re-trigger `hugo-obsidian` to update the content index. This lead to a lot of weird cases where the watch mode output wasn't accurate. Quartz 4 now uses a cohesive parse, filter, and emit pipeline which gets run on every change so hot-reloads are always accurate. 3. **Replacing Go template syntax with JSX**: Quartz 3 used [Go templates](https://pkg.go.dev/text/template) to create layouts for pages. However, the syntax isn't great for doing any sort of complex rendering (like [text processing](https://github.com/jackyzha0/quartz/blob/hugo/layouts/partials/textprocessing.html)) and it got very difficult to make any meaningful layout changes to Quartz 3. Quartz 4 uses an extension of JavaScript syntax called JSX which allows you to write layout code that looks like HTML in JavaScript which is significantly easier to understand and maintain. 4. **A new extensible [[configuration]] and [[configuration#Plugins|plugin]] system**: Quartz 3 was hard to configure without technical knowledge of how Hugo's partials worked. Extensions were even hard to make. Quartz 4's configuration and plugin system is designed to be extended by users while making updating to new versions of Quartz easy. ## Things to update - You will need to update your deploy scripts. See the [[hosting]] guide for more details. - Ensure that your default branch on GitHub is updated from `hugo` to `v4`. - [[folder and tag listings|Folder and tag listings]] have also changed. - Folder descriptions should go under `content//index.md` where `` is the name of the folder. - Tag descriptions should go under `content/tags/.md` where `` is the name of the tag. - Some HTML layout may not be the same between Quartz 3 and Quartz 4. If you depended on a particular HTML hierarchy or class names, you may need to update your custom CSS to reflect these changes. - If you customized the layout of Quartz 3, you may need to translate these changes from Go templates back to JSX as Quartz 4 no longer uses Hugo. For components, check out the guide on [[creating components]] for more details on this. ================================================ FILE: docs/philosophy.md ================================================ --- title: Philosophy of Quartz --- ## A garden should be a true hypertext > The garden is the web as topology. Every walk through the garden creates new paths, new meanings, and when we add things to the garden we add them in a way that allows many future, unpredicted relationships. > > _(The Garden and the Stream)_ The problem with the file cabinet is that it focuses on efficiency of access and interoperability rather than generativity and creativity. Thinking is not linear, nor is it hierarchical. In fact, not many things are linear or hierarchical at all. Then why is it that most tools and thinking strategies assume a nice chronological or hierarchical order for my thought processes? The ideal tool for thought for me would embrace the messiness of my mind, and organically help insights emerge from chaos instead of forcing an artificial order. A rhizomatic, not arboresecent, form of note taking. My goal with a digital garden is not purely as an organizing system and information store (though it works nicely for that). I want my digital garden to be a playground for new ways ideas can connect together. As a result, existing formal organizing systems like Zettelkasten or the hierarchical folder structures of Notion don’t work well for me. There is way too much upfront friction that by the time I’ve thought about how to organize my thought into folders categories, I’ve lost it. Quartz embraces the inherent rhizomatic and web-like nature of our thinking and tries to encourage note-taking in a similar form. --- ## A garden should be shared The goal of digital gardening should be to tap into your network’s collective intelligence to create constructive feedback loops. If done well, I have a shareable representation of my thoughts that I can send out into the world and people can respond. Even for my most half-baked thoughts, this helps me create a feedback cycle to strengthen and fully flesh out that idea. Quartz is designed first and foremost as a tool for publishing [digital gardens](https://jzhao.xyz/posts/networked-thought) to the web. To me, digital gardening is not just passive knowledge collection. It’s a form of expression and sharing. > “[One] who works with the door open gets all kinds of interruptions, but [they] also occasionally gets clues as to what the world is and what might be important.” > — Richard Hamming **The goal of Quartz is to make sharing your digital garden free and simple.** --- ## A garden should be your own At its core, Quartz is designed to be easy to use enough for non-technical people to get going but also powerful enough that senior developers can tweak it to work how they'd like it to work. 1. If you like the default configuration of Quartz and just want to change the content, the only thing that you need to change is the contents of the `content` folder. 2. If you'd like to make basic configuration tweaks but don't want to edit source code, one can tweak the plugins and components in `quartz.config.ts` and `quartz.layout.ts` in a guided manner to their liking. 3. If you'd like to tweak the actual source code of the underlying plugins, components, or even build process, Quartz purposefully ships its full source code to the end user to allow customization at this level too. Most software either confines you to either 1. Makes it easy to tweak content but not the presentation 2. Gives you too many knobs to tune the presentation without good opinionated defaults **Quartz should feel powerful but ultimately be an intuitive tool fully within your control.** It should be a piece of [agentic software](https://jzhao.xyz/posts/agentic-computing). Ultimately, it should have the right affordances to nudge users towards good defaults but never dictate what the 'correct' way of using it is. ================================================ FILE: docs/plugins/AliasRedirects.md ================================================ --- title: AliasRedirects tags: - plugin/emitter --- This plugin emits HTML redirect pages for aliases and permalinks defined in the frontmatter of content files. For example, A `foo.md` has the following frontmatter ```md title="foo.md" --- title: "Foo" alias: - "bar" --- ``` The target `host.me/bar` will be redirected to `host.me/foo` Note that these are permanent redirect. The emitter supports the following aliases: - `aliases` - `alias` > [!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.AliasRedirects()`. - Source: [`quartz/plugins/emitters/aliases.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/aliases.ts). ================================================ FILE: docs/plugins/Assets.md ================================================ --- title: Assets tags: - plugin/emitter --- This plugin emits all non-Markdown static assets in your content folder (like images, videos, HTML, etc). The plugin respects the `ignorePatterns` in the global [[configuration]]. Note that all static assets will then be accessible through its path on your generated site, i.e: `host.me/path/to/static.pdf` > [!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.Assets()`. - Source: [`quartz/plugins/emitters/assets.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/assets.ts). ================================================ FILE: docs/plugins/CNAME.md ================================================ --- title: CNAME tags: - plugin/emitter --- This plugin emits a `CNAME` record that points your subdomain to the default domain of your site. If you want to use a custom domain name like `quartz.example.com` for the site, then this is needed. See [[hosting|Hosting]] for more information. > [!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.CNAME()`. - Source: [`quartz/plugins/emitters/cname.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/cname.ts). ================================================ FILE: docs/plugins/Citations.md ================================================ --- 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). ================================================ FILE: docs/plugins/ComponentResources.md ================================================ --- title: ComponentResources tags: - plugin/emitter --- This plugin manages and emits the static resources required for the Quartz framework. This includes CSS stylesheets and JavaScript scripts that enhance the functionality and aesthetics of the generated site. See also the `cdnCaching` option in the `theme` section of the [[configuration]]. > [!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.ComponentResources()`. - Source: [`quartz/plugins/emitters/componentResources.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/componentResources.ts). ================================================ FILE: docs/plugins/ContentIndex.md ================================================ --- title: ContentIndex tags: - plugin/emitter --- This plugin emits both RSS and an XML sitemap for your site. The [[RSS Feed]] allows users to subscribe to content on your site and the sitemap allows search engines to better index your site. The plugin also emits a `contentIndex.json` file which is used by dynamic frontend components like search and graph. This plugin emits a comprehensive index of the site's content, generating additional resources such as a sitemap, an RSS feed, and a > [!note] > For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page. This plugin accepts the following configuration options: - `enableSiteMap`: If `true` (default), generates a sitemap XML file (`sitemap.xml`) listing all site URLs for search engines in content discovery. - `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`. - `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. ## API - Category: Emitter - Function name: `Plugin.ContentIndex()`. - Source: [`quartz/plugins/emitters/contentIndex.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/contentIndex.ts). ================================================ FILE: docs/plugins/ContentPage.md ================================================ --- title: ContentPage tags: - plugin/emitter --- This plugin is a core component of the Quartz framework. It generates the HTML pages for each piece of Markdown content. It emits the full-page [[layout]], including headers, footers, and body content, among others. > [!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.ContentPage()`. - Source: [`quartz/plugins/emitters/contentPage.tsx`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/contentPage.tsx). ================================================ FILE: docs/plugins/CrawlLinks.md ================================================ --- title: CrawlLinks tags: - plugin/transformer --- This plugin parses links and processes them to point to the right places. It is also needed for embedded links (like images). See [[Obsidian 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: - `markdownLinkResolution`: Sets the strategy for resolving Markdown paths, can be `"absolute"` (default), `"relative"` or `"shortest"`. You should use the same setting here as in [[Obsidian compatibility|Obsidian]]. - `absolute`: Path relative to the root of the content folder. - `relative`: Path relative to the file you are linking from. - `shortest`: Name of the file. If this isn't enough to identify the file, use the full absolute path. - `prettyLinks`: If `true` (default), simplifies links by removing folder paths, making them more user friendly (e.g. `folder/deeply/nested/note` becomes `note`). - `openLinksInNewTab`: If `true`, configures external links to open in a new tab. Defaults to `false`. - `lazyLoad`: If `true`, adds lazy loading to resource elements (`img`, `video`, etc.) to improve page load performance. Defaults to `false`. - `externalLinkIcon`: Adds an icon next to external links when `true` (default) to visually distinguishing them from internal links. > [!warning] > Removing this plugin is _not_ recommended and will likely break the page. ## API - Category: Transformer - Function name: `Plugin.CrawlLinks()`. - Source: [`quartz/plugins/transformers/links.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/links.ts). ================================================ FILE: docs/plugins/CreatedModifiedDate.md ================================================ --- title: "CreatedModifiedDate" tags: - plugin/transformer --- This plugin determines the created, modified, and published dates for a document using three potential data sources: frontmatter metadata, Git history, and the filesystem. See [[authoring content#Syntax]] 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: - `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] > If you rely on `git` for dates, make sure `defaultDateType` is set to `modified` in `quartz.config.ts`. > > Depending on how you [[hosting|host]] your Quartz, the `filesystem` dates of your local files may not match the final dates. In these cases, it may be better to use `git` or `frontmatter` to guarantee correct dates. ## API - Category: Transformer - Function name: `Plugin.CreatedModifiedDate()`. - Source: [`quartz/plugins/transformers/lastmod.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/lastmod.ts). ================================================ FILE: docs/plugins/CustomOgImages.md ================================================ --- 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

Cool Header!

} ``` > [!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 (

{title}

{description}

) } ``` ### 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 (

{title}

    {Li.map((item, index) => { if (item) { return
  • {item}
  • } })}

{description}

) } ``` ================================================ FILE: docs/plugins/Description.md ================================================ --- title: Description tags: - plugin/transformer --- This plugin generates descriptions that are used as metadata for the HTML `head`, the [[RSS Feed]] and in [[folder and tag listings]] if there is no main body content, the description is used as the text between the title and the listing. If the frontmatter contains a `description` property, it is used (see [[authoring content#Syntax]]). Otherwise, the plugin will do its best to use the first few sentences of the content to reach the target description length. > [!note] > For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page. This plugin accepts the following configuration options: - `descriptionLength`: the maximum length of the generated description. Default is 150 characters. The cut off happens after the first _sentence_ that ends after the given length. - `replaceExternalLinks`: If `true` (default), replace external links with their domain and path in the description (e.g. `https://domain.tld/some_page/another_page?query=hello&target=world` is replaced with `domain.tld/some_page/another_page`). ## API - Category: Transformer - Function name: `Plugin.Description()`. - Source: [`quartz/plugins/transformers/description.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/description.ts). ================================================ FILE: docs/plugins/ExplicitPublish.md ================================================ --- title: ExplicitPublish tags: - plugin/filter --- This plugin filters content based on an explicit `publish` flag in the frontmatter, allowing only content that is explicitly marked for publication to pass through. It's the opt-in version of [[RemoveDrafts]]. See [[private pages]] for more information. > [!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: Filter - Function name: `Plugin.ExplicitPublish()`. - Source: [`quartz/plugins/filters/explicit.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/filters/explicit.ts). ================================================ FILE: docs/plugins/Favicon.md ================================================ --- 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). ================================================ FILE: docs/plugins/FolderPage.md ================================================ --- title: FolderPage tags: - plugin/emitter --- This plugin generates index pages for folders, creating a listing page for each folder that contains multiple content files. See [[folder and tag listings]] for more information. Example: [[advanced/|Advanced]] > [!note] > For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page. The pages are displayed using the `defaultListPageLayout` in `quartz.layouts.ts`. For the content, the `FolderContent` component is used. If you want to modify the layout, you must edit it directly (`quartz/components/pages/FolderContent.tsx`). This plugin accepts the following configuration options: - `sort`: A function of type `(f1: QuartzPluginData, f2: QuartzPluginData) => number{:ts}` used to sort entries. Defaults to sorting by date and tie-breaking on lexographical order. ## API - Category: Emitter - Function name: `Plugin.FolderPage()`. - Source: [`quartz/plugins/emitters/folderPage.tsx`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/folderPage.tsx). ================================================ FILE: docs/plugins/Frontmatter.md ================================================ --- title: "Frontmatter" tags: - plugin/transformer --- This plugin parses the frontmatter of the page using the [gray-matter](https://github.com/jonschlinkert/gray-matter) library. See [[authoring content#Syntax]], [[Obsidian compatibility]] and [[OxHugo 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: - `delimiters`: the delimiters to use for the frontmatter. Can have one value (e.g. `"---"`) or separate values for opening and closing delimiters (e.g. `["---", "~~~"]`). Defaults to `"---"`. - `language`: the language to use for parsing the frontmatter. Can be `yaml` (default) or `toml`. > [!warning] > 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 - Category: Transformer - Function name: `Plugin.Frontmatter()`. - Source: [`quartz/plugins/transformers/frontmatter.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/frontmatter.ts). ================================================ FILE: docs/plugins/GitHubFlavoredMarkdown.md ================================================ --- title: GitHubFlavoredMarkdown tags: - plugin/transformer --- This plugin enhances Markdown processing to support GitHub Flavored Markdown (GFM) which adds features like autolink literals, footnotes, strikethrough, tables and tasklists. In addition, this plugin adds optional features for typographic refinement (such as converting straight quotes to curly quotes, dashes to en-dashes/em-dashes, and ellipses) and automatic heading links as a symbol that appears next to the heading on hover. > [!note] > For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page. This plugin accepts the following configuration options: - `enableSmartyPants`: When true, enables typographic enhancements. Default is true. - `linkHeadings`: When true, automatically adds links to headings. Default is true. ## API - Category: Transformer - Function name: `Plugin.GitHubFlavoredMarkdown()`. - Source: [`quartz/plugins/transformers/gfm.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/gfm.ts). ================================================ FILE: docs/plugins/HardLineBreaks.md ================================================ --- title: HardLineBreaks tags: - plugin/transformer --- This plugin automatically converts single line breaks in Markdown text into hard line breaks in the HTML output. This plugin is not enabled by default as this doesn't follow the semantics of actual Markdown but you may enable it if you'd like parity with [[Obsidian compatibility|Obsidian]]. > [!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: Transformer - Function name: `Plugin.HardLineBreaks()`. - Source: [`quartz/plugins/transformers/linebreaks.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/linebreaks.ts). ================================================ FILE: docs/plugins/Latex.md ================================================ --- title: "Latex" tags: - plugin/transformer --- This plugin adds LaTeX support to Quartz. See [[features/Latex|Latex]] 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: - `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}"}` ## API - Category: Transformer - Function name: `Plugin.Latex()`. - Source: [`quartz/plugins/transformers/latex.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/latex.ts). ================================================ FILE: docs/plugins/NotFoundPage.md ================================================ --- title: NotFoundPage tags: - plugin/emitter --- This plugin emits a 404 (Not Found) page for broken or non-existent URLs. > [!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.NotFoundPage()`. - Source: [`quartz/plugins/emitters/404.tsx`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/404.tsx). ================================================ FILE: docs/plugins/ObsidianFlavoredMarkdown.md ================================================ --- title: ObsidianFlavoredMarkdown tags: - plugin/transformer --- This plugin provides support for [[Obsidian compatibility]]. > [!note] > For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page. This plugin accepts the following configuration options: - `comments`: If `true` (default), enables parsing of `%%` style Obsidian comment blocks. - `highlight`: If `true` (default), enables parsing of `==` style highlights within content. - `wikilinks`:If `true` (default), turns [[wikilinks]] into regular links. - `callouts`: If `true` (default), adds support for [[callouts|callout]] blocks for emphasizing content. - `mermaid`: If `true` (default), enables [[Mermaid diagrams|Mermaid diagram]] rendering within Markdown files. - `parseTags`: If `true` (default), parses and links tags within the content. - `parseArrows`: If `true` (default), transforms arrow symbols into their HTML character equivalents. - `parseBlockReferences`: If `true` (default), handles block references, linking to specific content blocks. - `enableInHtmlEmbed`: If `true`, allows embedding of content directly within HTML. Defaults to `false`. - `enableYouTubeEmbed`: If `true` (default), enables the embedding of YouTube videos and playlists using external image Markdown syntax. - `enableVideoEmbed`: If `true` (default), enables the embedding of video files. - `enableCheckbox`: If `true`, adds support for interactive checkboxes in content. Defaults to `false`. - `disableBrokenWikilinks`: If `true`, replaces links to non-existent notes with a dimmed, disabled link. Defaults to `false`. > [!warning] > Don't remove this plugin if you're using [[Obsidian compatibility|Obsidian]] to author the content! ## API - Category: Transformer - Function name: `Plugin.ObsidianFlavoredMarkdown()`. - Source: [`quartz/plugins/transformers/ofm.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/ofm.ts) ================================================ FILE: docs/plugins/OxHugoFlavoredMarkdown.md ================================================ --- title: OxHugoFlavoredMarkdown tags: - plugin/transformer --- This plugin provides support for [ox-hugo](https://github.com/kaushalmodi/ox-hugo) compatibility. See [[OxHugo 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: - `wikilinks`: If `true` (default), converts Hugo `{{ relref }}` shortcodes to Quartz [[wikilinks]]. - `removePredefinedAnchor`: If `true` (default), strips predefined anchors from headings. - `removeHugoShortcode`: If `true` (default), removes Hugo shortcode syntax (`{{}}`) from the content. - `replaceFigureWithMdImg`: If `true` (default), replaces `
` with `![]()`. - `replaceOrgLatex`: If `true` (default), converts Org-mode [[features/Latex|Latex]] fragments to Quartz-compatible LaTeX wrapped in `$` (for inline) and `$$` (for block equations). > [!warning] > While you can use this together with [[ObsidianFlavoredMarkdown]], it's not recommended because it might mutate the file in unexpected ways. Use with caution. > > If you use `toml` frontmatter, make sure to configure the [[Frontmatter]] plugin accordingly. See [[OxHugo compatibility]] for an example. ## API - Category: Transformer - Function name: `Plugin.OxHugoFlavoredMarkdown()`. - Source: [`quartz/plugins/transformers/oxhugofm.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/oxhugofm.ts). ================================================ FILE: docs/plugins/RemoveDrafts.md ================================================ --- title: RemoveDrafts tags: - plugin/filter --- This plugin filters out content from your vault, so that only finalized content is made available. This prevents [[private pages]] from being published. By default, it filters out all pages with `draft: true` in the frontmatter and leaves all other pages intact. > [!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: Filter - Function name: `Plugin.RemoveDrafts()`. - Source: [`quartz/plugins/filters/draft.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/filters/draft.ts). ================================================ FILE: docs/plugins/RoamFlavoredMarkdown.md ================================================ --- 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). ================================================ FILE: docs/plugins/Static.md ================================================ --- title: Static tags: - plugin/emitter --- This plugin emits all static resources needed by Quartz. This is used, for example, for fonts and images that need a stable position, such as banners and icons. The plugin respects the `ignorePatterns` in the global [[configuration]]. > [!important] > This is different from [[Assets]]. The resources from the [[Static]] plugin are located under `quartz/static`, whereas [[Assets]] renders all static resources under `content` and is used for images, videos, audio, etc. that are directly referenced by your markdown content. > [!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.Static()`. - Source: [`quartz/plugins/emitters/static.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/static.ts). ================================================ FILE: docs/plugins/SyntaxHighlighting.md ================================================ --- title: "SyntaxHighlighting" tags: - plugin/transformer --- This plugin is used to add syntax highlighting to code blocks in Quartz. See [[syntax highlighting]] 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: - `theme`: a separate id of one of the [themes bundled with Shikiji](https://shikiji.netlify.app/themes). One for light mode and one for dark mode. Defaults to `theme: { light: "github-light", dark: "github-dark" }`. - `keepBackground`: If set to `true`, the background of the Shikiji theme will be used. With `false` (default) the Quartz theme color for background will be used instead. In addition, you can further override the colours in the `quartz/styles/syntax.scss` file. ## API - Category: Transformer - Function name: `Plugin.SyntaxHighlighting()`. - Source: [`quartz/plugins/transformers/syntax.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/syntax.ts). ================================================ FILE: docs/plugins/TableOfContents.md ================================================ --- title: TableOfContents tags: - plugin/transformer --- This plugin generates a table of contents (TOC) for Markdown documents. See [[table of contents]] 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: - `maxDepth`: Limits the depth of headings included in the TOC, ranging from `1` (top level headings only) to `6` (all heading levels). Default is `3`. - `minEntries`: The minimum number of heading entries required for the TOC to be displayed. Default is `1`. - `showByDefault`: If `true` (default), the TOC should be displayed by default. Can be overridden by frontmatter settings. - `collapseByDefault`: If `true`, the TOC will start in a collapsed state. Default is `false`. > [!warning] > This plugin needs the `Component.TableOfContents` component in `quartz.layout.ts` to determine where to display the TOC. Without it, nothing will be displayed. They should always be added or removed together. ## API - Category: Transformer - Function name: `Plugin.TableOfContents()`. - Source: [`quartz/plugins/transformers/toc.ts`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/transformers/toc.ts). ================================================ FILE: docs/plugins/TagPage.md ================================================ --- title: TagPage tags: - plugin/emitter --- This plugin emits dedicated pages for each tag used in the content. See [[folder and tag listings]] for more information. > [!note] > For information on how to add, remove or configure plugins, see the [[configuration#Plugins|Configuration]] page. The pages are displayed using the `defaultListPageLayout` in `quartz.layouts.ts`. For the content, the `TagContent` component is used. If you want to modify the layout, you must edit it directly (`quartz/components/pages/TagContent.tsx`). This plugin accepts the following configuration options: - `sort`: A function of type `(f1: QuartzPluginData, f2: QuartzPluginData) => number{:ts}` used to sort entries. Defaults to sorting by date and tie-breaking on lexographical order. ## API - Category: Emitter - Function name: `Plugin.TagPage()`. - Source: [`quartz/plugins/emitters/tagPage.tsx`](https://github.com/jackyzha0/quartz/blob/v4/quartz/plugins/emitters/tagPage.tsx). ================================================ FILE: docs/plugins/index.md ================================================ --- title: Plugins --- ================================================ FILE: docs/setting up your GitHub repository.md ================================================ --- title: Setting up your GitHub repository --- First, make sure you have Quartz [[index#🪴 Get Started|cloned and setup locally]]. Then, create a new repository on GitHub.com. Do **not** initialize the new repository with `README`, license, or `gitignore` files. ![[github-init-repo-options.png]] At the top of your repository on GitHub.com's Quick Setup page, click the clipboard to copy the remote repository URL. ![[github-quick-setup.png]] In your terminal of choice, navigate to the root of your Quartz folder. Then, run the following commands, replacing `REMOTE-URL` with the URL you just copied from the previous step. ```bash # list all the repositories that are tracked git remote -v # if the origin doesn't match your own repository, set your repository as the origin git remote set-url origin REMOTE-URL # if you don't have upstream as a remote, add it so updates work git remote add upstream https://github.com/jackyzha0/quartz.git ``` Then, you can sync the content to upload it to your repository. This is a helper command that will do the initial push of your content to your repository. ```bash npx quartz sync --no-pull ``` > [!warning]- `fatal: --[no-]autostash option is only valid with --rebase` > 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. > [!hint] Flags and options > For full help options, you can run `npx quartz sync --help`. > > Most of these have sensible defaults but you can override them if you have a custom setup: > > - `-d` or `--directory`: the content folder. This is normally just `content` > - `-v` or `--verbose`: print out extra logging information > - `--commit` or `--no-commit`: whether to make a `git` commit for your changes > - `--push` or `--no-push`: whether to push updates to your GitHub fork of Quartz > - `--pull` or `--no-pull`: whether to try and pull in any updates from your GitHub fork (i.e. from other devices) before pushing ================================================ FILE: docs/showcase.md ================================================ --- title: "Quartz Showcase" --- Want to see what Quartz can do? Here are some cool community gardens: - [Quartz Documentation (this site!)](https://quartz.jzhao.xyz/) - [Jacky Zhao's Garden](https://jzhao.xyz/) - [Aaron Pham's Garden](https://aarnphm.xyz/) - [The Pond](https://turntrout.com/welcome) - [Eilleen's Everything Notebook](https://quartz.eilleeenz.com/) - [Morrowind Modding Wiki](https://morrowind-modding.github.io/) - [Stanford CME 302 Numerical Linear Algebra](https://ericdarve.github.io/NLA/) - [Socratica Toolbox](https://toolbox.socratica.info/) - [A Pattern Language - Christopher Alexander (Architecture)](https://patternlanguage.cc/) - [Sideny's 3D Artist's Handbook](https://sidney-eliot.github.io/3d-artists-handbook/) - [Brandon Boswell's Garden](https://brandonkboswell.com) - [Data Engineering Vault: A Second Brain Knowledge Network](https://vault.ssp.sh/) - [🪴Aster's notebook](https://notes.asterhu.com) - [Gatekeeper Wiki](https://www.gatekeeper.wiki) - [Ellie's Notes](https://ellie.wtf) - [Eledah's Crystalline](https://blog.eledah.ir/) - [🌓 Projects & Privacy - FOSS, tech, law](https://be-far.com) ================================================ FILE: docs/tags/component.md ================================================ --- title: Components --- Want to create your own custom component? Check out the advanced guide on [[creating components]] for more information. ================================================ FILE: docs/tags/plugin.md ================================================ --- title: Plugins --- ================================================ FILE: docs/upgrading.md ================================================ --- title: "Upgrading Quartz" --- > [!note] > This is specifically a guide for upgrading Quartz 4 version to a more recent update. If you are coming from Quartz 3, check out the [[migrating from Quartz 3|migration guide]] for more info. To fetch the latest Quartz updates, simply run ```bash npx quartz update ``` As Quartz uses [git](https://git-scm.com/) under the hood for versioning, updating effectively 'pulls' in the updates from the official Quartz GitHub repository. If you have local changes that might conflict with the updates, you may need to resolve these manually yourself (or, pull manually using `git pull origin upstream`). > [!hint] > Quartz will try to cache your content before updating to try and prevent merge conflicts. If you get a conflict mid-merge, you can stop the merge and then run `npx quartz restore` to restore your content from the cache. If you have the [GitHub desktop app](https://desktop.github.com/), this will automatically open to help you resolve the conflicts. Otherwise, you will need to resolve this in a text editor like VSCode. For more help on resolving conflicts manually, check out the [GitHub guide on resolving merge conflicts](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line#competing-line-change-merge-conflicts). ================================================ FILE: globals.d.ts ================================================ export declare global { interface Document { addEventListener( type: K, listener: (this: Document, ev: CustomEventMap[K]) => void, ): void removeEventListener( type: K, listener: (this: Document, ev: CustomEventMap[K]) => void, ): void dispatchEvent(ev: CustomEventMap[K] | UIEvent): void } interface Window { spaNavigate(url: URL, isBack: boolean = false) addCleanup(fn: (...args: any[]) => void) } } ================================================ FILE: index.d.ts ================================================ declare module "*.scss" { const content: string export = content } // dom custom event interface CustomEventMap { prenav: CustomEvent<{}> nav: CustomEvent<{ url: FullSlug }> themechange: CustomEvent<{ theme: "light" | "dark" }> readermodechange: CustomEvent<{ mode: "on" | "off" }> } type ContentIndex = Record declare const fetchData: Promise ================================================ FILE: package.json ================================================ { "name": "@jackyzha0/quartz", "description": "🌱 publish your digital garden and notes as a website", "private": true, "version": "4.5.2", "type": "module", "author": "jackyzha0 ", "license": "MIT", "homepage": "https://quartz.jzhao.xyz", "repository": { "type": "git", "url": "https://github.com/jackyzha0/quartz.git" }, "scripts": { "quartz": "./quartz/bootstrap-cli.mjs", "docs": "npx quartz build --serve -d docs", "check": "tsc --noEmit && npx prettier . --check", "format": "npx prettier . --write", "test": "tsx --test", "profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1" }, "engines": { "npm": ">=10.9.2", "node": ">=22" }, "keywords": [ "site generator", "ssg", "digital-garden", "markdown", "blog", "quartz" ], "bin": { "quartz": "./quartz/bootstrap-cli.mjs" }, "dependencies": { "@clack/prompts": "^0.11.0", "@floating-ui/dom": "^1.7.4", "@myriaddreamin/rehype-typst": "^0.6.0", "@napi-rs/simple-git": "0.1.22", "@tweenjs/tween.js": "^25.0.0", "ansi-truncate": "^1.4.0", "async-mutex": "^0.5.0", "chokidar": "^5.0.0", "cli-spinner": "^0.2.10", "d3": "^7.9.0", "esbuild-sass-plugin": "^3.6.0", "flexsearch": "^0.8.205", "github-slugger": "^2.0.0", "globby": "^16.1.0", "gray-matter": "^4.0.3", "hast-util-to-html": "^9.0.5", "hast-util-to-jsx-runtime": "^2.3.6", "hast-util-to-string": "^3.0.1", "is-absolute-url": "^5.0.0", "js-yaml": "^4.1.1", "lightningcss": "^1.31.1", "mdast-util-find-and-replace": "^3.0.2", "mdast-util-to-hast": "^13.2.1", "mdast-util-to-string": "^4.0.0", "micromorph": "^0.4.5", "minimatch": "^10.1.1", "pixi.js": "^8.15.0", "preact": "^10.28.2", "preact-render-to-string": "^6.6.5", "pretty-bytes": "^7.1.0", "pretty-time": "^1.1.0", "reading-time": "^1.5.0", "rehype-autolink-headings": "^7.1.0", "rehype-citation": "^2.3.1", "rehype-katex": "^7.0.1", "rehype-mathjax": "^7.1.0", "rehype-pretty-code": "^0.14.1", "rehype-raw": "^7.0.0", "rehype-slug": "^6.0.0", "remark": "^15.0.1", "remark-breaks": "^4.0.0", "remark-frontmatter": "^5.0.0", "remark-gfm": "^4.0.1", "remark-math": "^6.0.0", "remark-parse": "^11.0.0", "remark-rehype": "^11.1.2", "remark-smartypants": "^3.0.2", "rfdc": "^1.4.1", "satori": "^0.19.1", "serve-handler": "^6.1.6", "sharp": "^0.34.5", "shiki": "^1.26.2", "source-map-support": "^0.5.21", "to-vfile": "^8.0.0", "toml": "^3.0.0", "unified": "^11.0.5", "unist-util-visit": "^5.1.0", "vfile": "^6.0.3", "workerpool": "^10.0.1", "ws": "^8.19.0", "yargs": "^18.0.0" }, "devDependencies": { "@types/d3": "^7.4.3", "@types/hast": "^3.0.4", "@types/js-yaml": "^4.0.9", "@types/node": "^25.0.10", "@types/pretty-time": "^1.1.5", "@types/source-map-support": "^0.5.10", "@types/ws": "^8.18.1", "@types/yargs": "^17.0.35", "esbuild": "^0.27.2", "prettier": "^3.8.1", "tsx": "^4.21.0", "typescript": "^5.9.3" } } ================================================ FILE: quartz/bootstrap-cli.mjs ================================================ #!/usr/bin/env -S node --no-deprecation import yargs from "yargs" import { hideBin } from "yargs/helpers" import { handleBuild, handleCreate, handleUpdate, handleRestore, handleSync, } from "./cli/handlers.js" import { CommonArgv, BuildArgv, CreateArgv, SyncArgv } from "./cli/args.js" import { version } from "./cli/constants.js" yargs(hideBin(process.argv)) .scriptName("quartz") .version(version) .usage("$0 [args]") .command("create", "Initialize Quartz", CreateArgv, async (argv) => { await handleCreate(argv) }) .command("update", "Get the latest Quartz updates", CommonArgv, async (argv) => { await handleUpdate(argv) }) .command( "restore", "Try to restore your content folder from the cache", CommonArgv, async (argv) => { await handleRestore(argv) }, ) .command("sync", "Sync your Quartz to and from GitHub.", SyncArgv, async (argv) => { await handleSync(argv) }) .command("build", "Build Quartz into a bundle of static HTML files", BuildArgv, async (argv) => { await handleBuild(argv) }) .showHelpOnFail(false) .help() .strict() .demandCommand().argv ================================================ FILE: quartz/bootstrap-worker.mjs ================================================ #!/usr/bin/env node import workerpool from "workerpool" const cacheFile = "./.quartz-cache/transpiled-worker.mjs" const { parseMarkdown, processHtml } = await import(cacheFile) workerpool.worker({ parseMarkdown, processHtml, }) ================================================ FILE: quartz/build.ts ================================================ import sourceMapSupport from "source-map-support" sourceMapSupport.install(options) import path from "path" import { PerfTimer } from "./util/perf" import { rm } from "fs/promises" import { GlobbyFilterFunction, isGitIgnored } from "globby" import { styleText } from "util" import { parseMarkdown } from "./processors/parse" import { filterContent } from "./processors/filter" import { emitContent } from "./processors/emit" import cfg from "../quartz.config" import { FilePath, joinSegments, slugifyFilePath } from "./util/path" import chokidar from "chokidar" import { ProcessedContent } from "./plugins/vfile" import { Argv, BuildCtx } from "./util/ctx" import { glob, toPosixPath } from "./util/glob" import { trace } from "./util/trace" import { options } from "./util/sourcemap" import { Mutex } from "async-mutex" import { getStaticResourcesFromPlugins } from "./plugins" import { randomIdNonSecure } from "./util/random" import { ChangeEvent } from "./plugins/types" import { minimatch } from "minimatch" type ContentMap = Map< FilePath, | { type: "markdown" content: ProcessedContent } | { type: "other" } > type BuildData = { ctx: BuildCtx ignored: GlobbyFilterFunction mut: Mutex contentMap: ContentMap changesSinceLastBuild: Record lastBuildMs: number } async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) { const ctx: BuildCtx = { buildId: randomIdNonSecure(), argv, cfg, allSlugs: [], allFiles: [], incremental: false, } const perf = new PerfTimer() const output = argv.output const pluginCount = Object.values(cfg.plugins).flat().length const pluginNames = (key: "transformers" | "filters" | "emitters") => cfg.plugins[key].map((plugin) => plugin.name) if (argv.verbose) { console.log(`Loaded ${pluginCount} plugins`) console.log(` Transformers: ${pluginNames("transformers").join(", ")}`) console.log(` Filters: ${pluginNames("filters").join(", ")}`) console.log(` Emitters: ${pluginNames("emitters").join(", ")}`) } const release = await mut.acquire() perf.addEvent("clean") await rm(output, { recursive: true, force: true }) console.log(`Cleaned output directory \`${output}\` in ${perf.timeSince("clean")}`) perf.addEvent("glob") const allFiles = await glob("**/*.*", argv.directory, cfg.configuration.ignorePatterns) const markdownPaths = allFiles.filter((fp) => fp.endsWith(".md")).sort() console.log( `Found ${markdownPaths.length} input files from \`${argv.directory}\` in ${perf.timeSince("glob")}`, ) const filePaths = markdownPaths.map((fp) => joinSegments(argv.directory, fp) as FilePath) ctx.allFiles = allFiles ctx.allSlugs = allFiles.map((fp) => slugifyFilePath(fp as FilePath)) const parsedFiles = await parseMarkdown(ctx, filePaths) const filteredContent = filterContent(ctx, parsedFiles) await emitContent(ctx, filteredContent) console.log( styleText("green", `Done processing ${markdownPaths.length} files in ${perf.timeSince()}`), ) release() if (argv.watch) { ctx.incremental = true return startWatching(ctx, mut, parsedFiles, clientRefresh) } } // setup watcher for rebuilds async function startWatching( ctx: BuildCtx, mut: Mutex, initialContent: ProcessedContent[], clientRefresh: () => void, ) { const { argv, allFiles } = ctx const contentMap: ContentMap = new Map() for (const filePath of allFiles) { contentMap.set(filePath, { type: "other", }) } for (const content of initialContent) { const [_tree, vfile] = content contentMap.set(vfile.data.relativePath!, { type: "markdown", content, }) } const gitIgnoredMatcher = await isGitIgnored() const buildData: BuildData = { ctx, mut, contentMap, ignored: (fp) => { const pathStr = toPosixPath(fp.toString()) if (pathStr.startsWith(".git/")) return true if (gitIgnoredMatcher(pathStr)) return true for (const pattern of cfg.configuration.ignorePatterns) { if (minimatch(pathStr, pattern)) { return true } } return false }, changesSinceLastBuild: {}, lastBuildMs: 0, } const watcher = chokidar.watch(".", { awaitWriteFinish: { stabilityThreshold: 250 }, persistent: true, cwd: argv.directory, ignoreInitial: true, }) const changes: ChangeEvent[] = [] watcher .on("add", (fp) => { fp = toPosixPath(fp) if (buildData.ignored(fp)) return changes.push({ path: fp as FilePath, type: "add" }) void rebuild(changes, clientRefresh, buildData) }) .on("change", (fp) => { fp = toPosixPath(fp) if (buildData.ignored(fp)) return changes.push({ path: fp as FilePath, type: "change" }) void rebuild(changes, clientRefresh, buildData) }) .on("unlink", (fp) => { fp = toPosixPath(fp) if (buildData.ignored(fp)) return changes.push({ path: fp as FilePath, type: "delete" }) void rebuild(changes, clientRefresh, buildData) }) return async () => { await watcher.close() } } async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildData: BuildData) { const { ctx, contentMap, mut, changesSinceLastBuild } = buildData const { argv, cfg } = ctx const buildId = randomIdNonSecure() ctx.buildId = buildId buildData.lastBuildMs = new Date().getTime() const numChangesInBuild = changes.length const release = await mut.acquire() // if there's another build after us, release and let them do it if (ctx.buildId !== buildId) { release() return } const perf = new PerfTimer() perf.addEvent("rebuild") console.log(styleText("yellow", "Detected change, rebuilding...")) // update changesSinceLastBuild for (const change of changes) { changesSinceLastBuild[change.path] = change.type } const staticResources = getStaticResourcesFromPlugins(ctx) const pathsToParse: FilePath[] = [] for (const [fp, type] of Object.entries(changesSinceLastBuild)) { if (type === "delete" || path.extname(fp) !== ".md") continue const fullPath = joinSegments(argv.directory, toPosixPath(fp)) as FilePath pathsToParse.push(fullPath) } const parsed = await parseMarkdown(ctx, pathsToParse) for (const content of parsed) { contentMap.set(content[1].data.relativePath!, { type: "markdown", content, }) } // update state using changesSinceLastBuild // 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)) let processedFiles = filterContent( ctx, Array.from(contentMap.values()) .filter((file) => file.type === "markdown") .map((file) => file.content), ) let emittedFiles = 0 for (const emitter of cfg.plugins.emitters) { // Try to use partialEmit if available, otherwise assume the output is static const emitFn = emitter.partialEmit ?? emitter.emit const emitted = await emitFn(ctx, processedFiles, staticResources, changeEvents) if (emitted === null) { continue } if (Symbol.asyncIterator in emitted) { // Async generator case for await (const file of emitted) { emittedFiles++ if (ctx.argv.verbose) { console.log(`[emit:${emitter.name}] ${file}`) } } } else { // Array case emittedFiles += emitted.length if (ctx.argv.verbose) { for (const file of emitted) { console.log(`[emit:${emitter.name}] ${file}`) } } } } console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`) console.log(styleText("green", `Done rebuilding in ${perf.timeSince()}`)) changes.splice(0, numChangesInBuild) clientRefresh() release() } export default async (argv: Argv, mut: Mutex, clientRefresh: () => void) => { try { return await buildQuartz(argv, mut, clientRefresh) } catch (err) { trace("\nExiting Quartz due to a fatal error", err as Error) } } ================================================ FILE: quartz/cfg.ts ================================================ import { ValidDateType } from "./components/Date" import { QuartzComponent } from "./components/types" import { ValidLocale } from "./i18n" import { PluginTypes } from "./plugins/types" import { Theme } from "./util/theme" export type Analytics = | null | { provider: "plausible" host?: string } | { provider: "google" tagId: string } | { provider: "umami" websiteId: string host?: string } | { provider: "goatcounter" websiteId: string host?: string scriptSrc?: string } | { provider: "posthog" apiKey: string host?: string } | { provider: "tinylytics" siteId: string } | { provider: "cabin" host?: string } | { provider: "clarity" projectId?: string } | { provider: "matomo" host: string siteId: string } | { provider: "vercel" } | { provider: "rybbit" siteId: string host?: string } export interface GlobalConfiguration { pageTitle: string pageTitleSuffix?: string /** Whether to enable single-page-app style rendering. this prevents flashes of unstyled content and improves smoothness of Quartz */ enableSPA: boolean /** Whether to display Wikipedia-style popovers when hovering over links */ enablePopovers: boolean /** Analytics mode */ analytics: Analytics /** Glob patterns to not search */ ignorePatterns: string[] /** Whether to use created, modified, or published as the default type of date */ defaultDateType: ValidDateType /** Base URL to use for CNAME files, sitemaps, and RSS feeds that require an absolute URL. * Quartz will avoid using this as much as possible and use relative URLs most of the time */ baseUrl?: string theme: Theme /** * Allow to translate the date in the language of your choice. * Also used for UI translation (default: en-US) * 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) * 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 */ locale: ValidLocale } export interface QuartzConfig { configuration: GlobalConfiguration plugins: PluginTypes } export interface FullPageLayout { head: QuartzComponent header: QuartzComponent[] beforeBody: QuartzComponent[] pageBody: QuartzComponent afterBody: QuartzComponent[] left: QuartzComponent[] right: QuartzComponent[] footer: QuartzComponent } export type PageLayout = Pick export type SharedLayout = Pick ================================================ FILE: quartz/cli/args.js ================================================ export const CommonArgv = { directory: { string: true, alias: ["d"], default: "content", describe: "directory to look for content files", }, verbose: { boolean: true, alias: ["v"], default: false, describe: "print out extra logging information", }, } export const CreateArgv = { ...CommonArgv, source: { string: true, alias: ["s"], describe: "source directory to copy/create symlink from", }, strategy: { string: true, alias: ["X"], choices: ["new", "copy", "symlink"], describe: "strategy for content folder setup", }, links: { string: true, alias: ["l"], choices: ["absolute", "shortest", "relative"], describe: "strategy to resolve links", }, } export const SyncArgv = { ...CommonArgv, commit: { boolean: true, default: true, describe: "create a git commit for your unsaved changes", }, message: { string: true, alias: ["m"], describe: "option to override the default Quartz commit message", }, push: { boolean: true, default: true, describe: "push updates to your Quartz fork", }, pull: { boolean: true, default: true, describe: "pull updates from your Quartz fork", }, } export const BuildArgv = { ...CommonArgv, output: { string: true, alias: ["o"], default: "public", describe: "output folder for files", }, serve: { boolean: true, default: false, describe: "run a local server to live-preview your Quartz", }, watch: { boolean: true, default: false, describe: "watch for changes and rebuild automatically", }, baseDir: { string: true, default: "", describe: "base path to serve your local server on", }, port: { number: true, default: 8080, describe: "port to serve Quartz on", }, wsPort: { number: true, default: 3001, describe: "port to use for WebSocket-based hot-reload notifications", }, remoteDevHost: { string: true, default: "", describe: "A URL override for the websocket connection if you are not developing on localhost", }, bundleInfo: { boolean: true, default: false, describe: "show detailed bundle information", }, concurrency: { number: true, describe: "how many threads to use to parse notes", }, } ================================================ FILE: quartz/cli/constants.js ================================================ import path from "path" import { readFileSync } from "fs" /** * All constants relating to helpers or handlers */ export const ORIGIN_NAME = "origin" export const UPSTREAM_NAME = "upstream" export const QUARTZ_SOURCE_BRANCH = "v4" export const cwd = process.cwd() export const cacheDir = path.join(cwd, ".quartz-cache") export const cacheFile = "./quartz/.quartz-cache/transpiled-build.mjs" export const fp = "./quartz/build.ts" export const { version } = JSON.parse(readFileSync("./package.json").toString()) export const contentCacheFolder = path.join(cacheDir, "content-cache") ================================================ FILE: quartz/cli/handlers.js ================================================ import { promises } from "fs" import path from "path" import esbuild from "esbuild" import { styleText } from "util" import { sassPlugin } from "esbuild-sass-plugin" import fs from "fs" import { intro, outro, select, text } from "@clack/prompts" import { rm } from "fs/promises" import chokidar from "chokidar" import prettyBytes from "pretty-bytes" import { execSync, spawnSync } from "child_process" import http from "http" import serveHandler from "serve-handler" import { WebSocketServer } from "ws" import { randomUUID } from "crypto" import { Mutex } from "async-mutex" import { CreateArgv } from "./args.js" import { globby } from "globby" import { exitIfCancel, escapePath, gitPull, popContentFolder, stashContentFolder, } from "./helpers.js" import { UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH, ORIGIN_NAME, version, fp, cacheFile, cwd, } 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` * @param {*} argv arguments for `create` */ export async function handleCreate(argv) { console.log() intro(styleText(["bgGreen", "black"], ` Quartz v${version} `)) const contentFolder = resolveContentPath(argv.directory) let setupStrategy = argv.strategy?.toLowerCase() let linkResolutionStrategy = argv.links?.toLowerCase() const sourceDirectory = argv.source // If all cmd arguments were provided, check if they're valid if (setupStrategy && linkResolutionStrategy) { // If setup isn't, "new", source argument is required if (setupStrategy !== "new") { // Error handling if (!sourceDirectory) { outro( styleText( "red", `Setup strategies (arg '${styleText( "yellow", `-${CreateArgv.strategy.alias[0]}`, )}') other than '${styleText( "yellow", "new", )}' require content folder argument ('${styleText( "yellow", `-${CreateArgv.source.alias[0]}`, )}') to be set`, ), ) process.exit(1) } else { if (!fs.existsSync(sourceDirectory)) { outro( styleText( "red", `Input directory to copy/symlink 'content' from not found ('${styleText( "yellow", sourceDirectory, )}', invalid argument "${styleText("yellow", `-${CreateArgv.source.alias[0]}`)})`, ), ) process.exit(1) } else if (!fs.lstatSync(sourceDirectory).isDirectory()) { outro( styleText( "red", `Source directory to copy/symlink 'content' from is not a directory (found file at '${styleText( "yellow", sourceDirectory, )}', invalid argument ${styleText("yellow", `-${CreateArgv.source.alias[0]}`)}")`, ), ) process.exit(1) } } } } // Use cli process if cmd args werent provided if (!setupStrategy) { setupStrategy = exitIfCancel( await select({ message: `Choose how to initialize the content in \`${contentFolder}\``, options: [ { value: "new", label: "Empty Quartz" }, { value: "copy", label: "Copy an existing folder", hint: "overwrites `content`" }, { value: "symlink", label: "Symlink an existing folder", hint: "don't select this unless you know what you are doing!", }, ], }), ) } async function rmContentFolder() { const contentStat = await fs.promises.lstat(contentFolder) if (contentStat.isSymbolicLink()) { await fs.promises.unlink(contentFolder) } else { await rm(contentFolder, { recursive: true, force: true }) } } const gitkeepPath = path.join(contentFolder, ".gitkeep") if (fs.existsSync(gitkeepPath)) { await fs.promises.unlink(gitkeepPath) } if (setupStrategy === "copy" || setupStrategy === "symlink") { let originalFolder = sourceDirectory // If input directory was not passed, use cli if (!sourceDirectory) { originalFolder = escapePath( exitIfCancel( await text({ message: "Enter the full path to existing content folder", placeholder: "On most terminal emulators, you can drag and drop a folder into the window and it will paste the full path", validate(fp) { const fullPath = escapePath(fp) if (!fs.existsSync(fullPath)) { return "The given path doesn't exist" } else if (!fs.lstatSync(fullPath).isDirectory()) { return "The given path is not a folder" } }, }), ), ) } await rmContentFolder() if (setupStrategy === "copy") { await fs.promises.cp(originalFolder, contentFolder, { recursive: true, preserveTimestamps: true, }) } else if (setupStrategy === "symlink") { await fs.promises.symlink(originalFolder, contentFolder, "dir") } } else if (setupStrategy === "new") { await fs.promises.writeFile( path.join(contentFolder, "index.md"), `--- title: Welcome to Quartz --- This is a blank Quartz installation. See the [documentation](https://quartz.jzhao.xyz) for how to get started. `, ) } // Use cli process if cmd args werent provided if (!linkResolutionStrategy) { // get a preferred link resolution strategy linkResolutionStrategy = exitIfCancel( await select({ message: `Choose how Quartz should resolve links in your content. This should match Obsidian's link format. You can change this later in \`quartz.config.ts\`.`, options: [ { value: "shortest", label: "Treat links as shortest path", hint: "(default)", }, { value: "absolute", label: "Treat links as absolute path", }, { value: "relative", label: "Treat links as relative paths", }, ], }), ) } // now, do config changes const configFilePath = path.join(cwd, "quartz.config.ts") let configContent = await fs.promises.readFile(configFilePath, { encoding: "utf-8" }) configContent = configContent.replace( /markdownLinkResolution: '(.+)'/, `markdownLinkResolution: '${linkResolutionStrategy}'`, ) await fs.promises.writeFile(configFilePath, configContent) // setup remote execSync( `git remote show upstream || git remote add upstream https://github.com/jackyzha0/quartz.git`, { stdio: "ignore" }, ) outro(`You're all set! Not sure what to do next? Try: • Customizing Quartz a bit more by editing \`quartz.config.ts\` • Running \`npx quartz build --serve\` to preview your Quartz locally • Hosting your Quartz online (see: https://quartz.jzhao.xyz/hosting) `) } /** * Handles `npx quartz build` * @param {*} argv arguments for `build` */ export async function handleBuild(argv) { if (argv.serve) { argv.watch = true } console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)} \n`) const ctx = await esbuild.context({ entryPoints: [fp], outfile: cacheFile, bundle: true, keepNames: true, minifyWhitespace: true, minifySyntax: true, platform: "node", format: "esm", jsx: "automatic", jsxImportSource: "preact", packages: "external", metafile: true, sourcemap: true, sourcesContent: false, plugins: [ sassPlugin({ type: "css-text", cssImports: true, }), sassPlugin({ filter: /\.inline\.scss$/, type: "css", cssImports: true, }), { name: "inline-script-loader", setup(build) { build.onLoad({ filter: /\.inline\.(ts|js)$/ }, async (args) => { let text = await promises.readFile(args.path, "utf8") // remove default exports that we manually inserted text = text.replace("export default", "") text = text.replace("export", "") const sourcefile = path.relative(path.resolve("."), args.path) const resolveDir = path.dirname(sourcefile) const transpiled = await esbuild.build({ stdin: { contents: text, loader: "ts", resolveDir, sourcefile, }, write: false, bundle: true, minify: true, platform: "browser", format: "esm", }) const rawMod = transpiled.outputFiles[0].text return { contents: rawMod, loader: "text", } }) }, }, ], }) const buildMutex = new Mutex() let lastBuildMs = 0 let cleanupBuild = null const build = async (clientRefresh) => { const buildStart = new Date().getTime() lastBuildMs = buildStart const release = await buildMutex.acquire() if (lastBuildMs > buildStart) { release() return } if (cleanupBuild) { console.log(styleText("yellow", "Detected a source code change, doing a hard rebuild...")) await cleanupBuild() } const result = await ctx.rebuild().catch((err) => { console.error(`${styleText("red", "Couldn't parse Quartz configuration:")} ${fp}`) console.log(`Reason: ${styleText("gray", err)}`) process.exit(1) }) release() if (argv.bundleInfo) { const outputFileName = "quartz/.quartz-cache/transpiled-build.mjs" const meta = result.metafile.outputs[outputFileName] console.log( `Successfully transpiled ${Object.keys(meta.inputs).length} files (${prettyBytes( meta.bytes, )})`, ) console.log(await esbuild.analyzeMetafile(result.metafile, { color: true })) } // bypass module cache // https://github.com/nodejs/modules/issues/307 const { default: buildQuartz } = await import(`../../${cacheFile}?update=${randomUUID()}`) // ^ this import is relative, so base "cacheFile" path can't be used cleanupBuild = await buildQuartz(argv, buildMutex, clientRefresh) clientRefresh() } let clientRefresh = () => {} if (argv.serve) { const connections = [] clientRefresh = () => connections.forEach((conn) => conn.send("rebuild")) if (argv.baseDir !== "" && !argv.baseDir.startsWith("/")) { argv.baseDir = "/" + argv.baseDir } await build(clientRefresh) const server = http.createServer(async (req, res) => { if (argv.baseDir && !req.url?.startsWith(argv.baseDir)) { console.log( styleText( "red", `[404] ${req.url} (warning: link outside of site, this is likely a Quartz bug)`, ), ) res.writeHead(404) res.end() return } // strip baseDir prefix req.url = req.url?.slice(argv.baseDir.length) const serve = async () => { const release = await buildMutex.acquire() await serveHandler(req, res, { public: argv.output, directoryListing: false, headers: [ { source: "**/*.*", 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 statusString = status >= 200 && status < 300 ? styleText("green", `[${status}]`) : styleText("red", `[${status}]`) console.log(statusString + styleText("gray", ` ${argv.baseDir}${req.url}`)) release() } const redirect = (newFp) => { newFp = argv.baseDir + newFp res.writeHead(302, { Location: newFp, }) console.log( styleText("yellow", "[302]") + styleText("gray", ` ${argv.baseDir}${req.url} -> ${newFp}`), ) res.end() } let fp = req.url?.split("?")[0] ?? "/" // handle redirects if (fp.endsWith("/")) { // /trailing/ // does /trailing/index.html exist? if so, serve it const indexFp = path.posix.join(fp, "index.html") if (fs.existsSync(path.posix.join(argv.output, indexFp))) { req.url = fp return serve() } // does /trailing.html exist? if so, redirect to /trailing let base = fp.slice(0, -1) if (path.extname(base) === "") { base += ".html" } if (fs.existsSync(path.posix.join(argv.output, base))) { return redirect(fp.slice(0, -1)) } } else { // /regular // does /regular.html exist? if so, serve it let base = fp if (path.extname(base) === "") { base += ".html" } if (fs.existsSync(path.posix.join(argv.output, base))) { req.url = fp return serve() } // does /regular/index.html exist? if so, redirect to /regular/ let indexFp = path.posix.join(fp, "index.html") if (fs.existsSync(path.posix.join(argv.output, indexFp))) { return redirect(fp + "/") } } return serve() }) server.listen(argv.port) const wss = new WebSocketServer({ port: argv.wsPort }) wss.on("connection", (ws) => connections.push(ws)) console.log( styleText( "cyan", `Started a Quartz server listening at http://localhost:${argv.port}${argv.baseDir}`, ), ) } else { await build(clientRefresh) 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(styleText("gray", "hint: exit with ctrl+c")) } } /** * Handles `npx quartz update` * @param {*} argv arguments for `update` */ export async function handleUpdate(argv) { const contentFolder = resolveContentPath(argv.directory) console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)} \n`) console.log("Backing up your content") execSync( `git remote show upstream || git remote add upstream https://github.com/jackyzha0/quartz.git`, ) await stashContentFolder(contentFolder) console.log( "Pulling updates... you may need to resolve some `git` conflicts if you've made changes to components or plugins.", ) try { gitPull(UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH) } catch { console.log(styleText("red", "An error occurred above while pulling updates.")) await popContentFolder(contentFolder) return } await popContentFolder(contentFolder) console.log("Ensuring dependencies are up to date") /* 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) { console.log(styleText("green", "Done!")) } else { console.log(styleText("red", "An error occurred above while installing dependencies.")) } } /** * Handles `npx quartz restore` * @param {*} argv arguments for `restore` */ export async function handleRestore(argv) { const contentFolder = resolveContentPath(argv.directory) await popContentFolder(contentFolder) } /** * Handles `npx quartz sync` * @param {*} argv arguments for `sync` */ export async function handleSync(argv) { const contentFolder = resolveContentPath(argv.directory) console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)}\n`) console.log("Backing up your content") if (argv.commit) { const contentStat = await fs.promises.lstat(contentFolder) if (contentStat.isSymbolicLink()) { const linkTarg = await fs.promises.readlink(contentFolder) console.log(styleText("yellow", "Detected symlink, trying to dereference before committing")) // stash symlink file await stashContentFolder(contentFolder) // follow symlink and copy content await fs.promises.cp(linkTarg, contentFolder, { recursive: true, preserveTimestamps: true, }) } const currentTimestamp = new Date().toLocaleString("en-US", { dateStyle: "medium", timeStyle: "short", }) const commitMessage = argv.message ?? `Quartz sync: ${currentTimestamp}` spawnSync("git", ["add", "."], { stdio: "inherit" }) spawnSync("git", ["commit", "-m", commitMessage], { stdio: "inherit" }) if (contentStat.isSymbolicLink()) { // put symlink back await popContentFolder(contentFolder) } } await stashContentFolder(contentFolder) if (argv.pull) { console.log( "Pulling updates from your repository. You may need to resolve some `git` conflicts if you've made changes to components or plugins.", ) try { gitPull(ORIGIN_NAME, QUARTZ_SOURCE_BRANCH) } catch { console.log(styleText("red", "An error occurred above while pulling updates.")) await popContentFolder(contentFolder) return } } await popContentFolder(contentFolder) if (argv.push) { console.log("Pushing your changes") const currentBranch = execSync("git rev-parse --abbrev-ref HEAD").toString().trim() const res = spawnSync("git", ["push", "-uf", ORIGIN_NAME, currentBranch], { stdio: "inherit", }) if (res.status !== 0) { console.log( styleText("red", `An error occurred above while pushing to remote ${ORIGIN_NAME}.`), ) return } } console.log(styleText("green", "Done!")) } ================================================ FILE: quartz/cli/helpers.js ================================================ import { isCancel, outro } from "@clack/prompts" import { styleText } from "util" import { contentCacheFolder } from "./constants.js" import { spawnSync } from "child_process" import fs from "fs" export function escapePath(fp) { return fp .replace(/\\ /g, " ") // unescape spaces .replace(/^"(.*)"$/, "$1") .replace(/^'(.*)'$/, "$1") .trim() } export function exitIfCancel(val) { if (isCancel(val)) { outro(styleText("red", "Exiting")) process.exit(0) } else { return val } } export async function stashContentFolder(contentFolder) { await fs.promises.rm(contentCacheFolder, { force: true, recursive: true }) await fs.promises.cp(contentFolder, contentCacheFolder, { force: true, recursive: true, verbatimSymlinks: true, preserveTimestamps: true, }) await fs.promises.rm(contentFolder, { force: true, recursive: true }) } export function gitPull(origin, branch) { const flags = ["--no-rebase", "--autostash", "-s", "recursive", "-X", "ours", "--no-edit"] const out = spawnSync("git", ["pull", ...flags, origin, branch], { stdio: "inherit" }) if (out.stderr) { throw new Error(styleText("red", `Error while pulling updates: ${out.stderr}`)) } else if (out.status !== 0) { throw new Error(styleText("red", "Error while pulling updates")) } } export async function popContentFolder(contentFolder) { await fs.promises.rm(contentFolder, { force: true, recursive: true }) await fs.promises.cp(contentCacheFolder, contentFolder, { force: true, recursive: true, verbatimSymlinks: true, preserveTimestamps: true, }) await fs.promises.rm(contentCacheFolder, { force: true, recursive: true }) } ================================================ FILE: quartz/components/ArticleTitle.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { classNames } from "../util/lang" const ArticleTitle: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => { const title = fileData.frontmatter?.title if (title) { return

{title}

} else { return null } } ArticleTitle.css = ` .article-title { margin: 2rem 0 0 0; } ` export default (() => ArticleTitle) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Backlinks.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import style from "./styles/backlinks.scss" import { resolveRelative, simplifySlug } from "../util/path" import { i18n } from "../i18n" import { classNames } from "../util/lang" import OverflowListFactory from "./OverflowList" interface BacklinksOptions { hideWhenEmpty: boolean } const defaultOptions: BacklinksOptions = { hideWhenEmpty: true, } export default ((opts?: Partial) => { 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 (

{i18n(cfg.locale).components.backlinks.title}

{backlinkFiles.length > 0 ? ( backlinkFiles.map((f) => (
  • {f.frontmatter?.title}
  • )) ) : (
  • {i18n(cfg.locale).components.backlinks.noBacklinksFound}
  • )}
    ) } Backlinks.css = style Backlinks.afterDOMLoaded = overflowListAfterDOMLoaded return Backlinks }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Body.tsx ================================================ // @ts-ignore import clipboardScript from "./scripts/clipboard.inline" import clipboardStyle from "./styles/clipboard.scss" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" const Body: QuartzComponent = ({ children }: QuartzComponentProps) => { return
    {children}
    } Body.afterDOMLoaded = clipboardScript Body.css = clipboardStyle export default (() => Body) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Breadcrumbs.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import breadcrumbsStyle from "./styles/breadcrumbs.scss" import { FullSlug, SimpleSlug, resolveRelative, simplifySlug } from "../util/path" import { classNames } from "../util/lang" import { trieFromAllFiles } from "../util/ctx" type CrumbData = { displayName: string path: string } interface BreadcrumbOptions { /** * Symbol between crumbs */ spacerSymbol: string /** * Name of first crumb */ rootName: string /** * Whether to look up frontmatter title for folders (could cause performance problems with big vaults) */ resolveFrontmatterTitle: boolean /** * Whether to display the current page in the breadcrumbs. */ showCurrentPage: boolean } const defaultOptions: BreadcrumbOptions = { spacerSymbol: "❯", rootName: "Home", resolveFrontmatterTitle: true, showCurrentPage: true, } function formatCrumb(displayName: string, baseSlug: FullSlug, currentSlug: SimpleSlug): CrumbData { return { displayName: displayName.replaceAll("-", " "), path: resolveRelative(baseSlug, currentSlug), } } export default ((opts?: Partial) => { const options: BreadcrumbOptions = { ...defaultOptions, ...opts } const Breadcrumbs: QuartzComponent = ({ fileData, allFiles, displayClass, ctx, }: QuartzComponentProps) => { const trie = (ctx.trie ??= trieFromAllFiles(allFiles)) const slugParts = fileData.slug!.split("/") const pathNodes = trie.ancestryChain(slugParts) if (!pathNodes) { return null } const crumbs: CrumbData[] = pathNodes.map((node, idx) => { const crumb = formatCrumb(node.displayName, fileData.slug!, simplifySlug(node.slug)) if (idx === 0) { crumb.displayName = options.rootName } // For last node (current page), set empty path if (idx === pathNodes.length - 1) { crumb.path = "" } return crumb }) if (!options.showCurrentPage) { crumbs.pop() } return ( ) } Breadcrumbs.css = breadcrumbsStyle return Breadcrumbs }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Comments.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { classNames } from "../util/lang" // @ts-ignore import script from "./scripts/comments.inline" type Options = { provider: "giscus" options: { repo: `${string}/${string}` repoId: string category: string categoryId: string themeUrl?: string lightTheme?: string darkTheme?: string mapping?: "url" | "title" | "og:title" | "specific" | "number" | "pathname" strict?: boolean reactionsEnabled?: boolean inputPosition?: "top" | "bottom" lang?: string } } function boolToStringBool(b: boolean): string { return b ? "1" : "0" } export default ((opts: Options) => { 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 (
    ) } Comments.afterDOMLoaded = script return Comments }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/ConditionalRender.tsx ================================================ 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 } return null } ConditionalRender.afterDOMLoaded = config.component.afterDOMLoaded ConditionalRender.beforeDOMLoaded = config.component.beforeDOMLoaded ConditionalRender.css = config.component.css return ConditionalRender }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/ContentMeta.tsx ================================================ import { Date, getDate } from "./Date" import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import readingTime from "reading-time" import { classNames } from "../util/lang" import { i18n } from "../i18n" import { JSX } from "preact" import style from "./styles/contentMeta.scss" interface ContentMetaOptions { /** * Whether to display reading time */ showReadingTime: boolean showComma: boolean } const defaultOptions: ContentMetaOptions = { showReadingTime: true, showComma: true, } export default ((opts?: Partial) => { // Merge options with defaults const options: ContentMetaOptions = { ...defaultOptions, ...opts } function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) { const text = fileData.text if (text) { const segments: (string | JSX.Element)[] = [] if (fileData.dates) { segments.push() } // Display reading time if enabled if (options.showReadingTime) { const { minutes, words: _words } = readingTime(text) const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({ minutes: Math.ceil(minutes), }) segments.push({displayedTime}) } return (

    {segments}

    ) } else { return null } } ContentMetadata.css = style return ContentMetadata }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Darkmode.tsx ================================================ // @ts-ignore import darkmodeScript from "./scripts/darkmode.inline" import styles from "./styles/darkmode.scss" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { i18n } from "../i18n" import { classNames } from "../util/lang" const Darkmode: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => { return ( ) } Darkmode.beforeDOMLoaded = darkmodeScript Darkmode.css = styles export default (() => Darkmode) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Date.tsx ================================================ import { GlobalConfiguration } from "../cfg" import { ValidLocale } from "../i18n" import { QuartzPluginData } from "../plugins/vfile" interface Props { date: Date locale?: ValidLocale } export type ValidDateType = keyof Required["dates"] export function getDate(cfg: GlobalConfiguration, data: QuartzPluginData): Date | undefined { if (!cfg.defaultDateType) { throw new Error( `Field 'defaultDateType' was not set in the configuration object of quartz.config.ts. See https://quartz.jzhao.xyz/configuration#general-configuration for more details.`, ) } return data.dates?.[cfg.defaultDateType] } export function formatDate(d: Date, locale: ValidLocale = "en-US"): string { return d.toLocaleDateString(locale, { year: "numeric", month: "short", day: "2-digit", }) } export function Date({ date, locale }: Props) { return } ================================================ FILE: quartz/components/DesktopOnly.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" export default ((component: QuartzComponent) => { const Component = component const DesktopOnly: QuartzComponent = (props: QuartzComponentProps) => { return } DesktopOnly.displayName = component.displayName DesktopOnly.afterDOMLoaded = component?.afterDOMLoaded DesktopOnly.beforeDOMLoaded = component?.beforeDOMLoaded DesktopOnly.css = component?.css return DesktopOnly }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Explorer.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import style from "./styles/explorer.scss" // @ts-ignore import script from "./scripts/explorer.inline" import { classNames } from "../util/lang" import { i18n } from "../i18n" import { FileTrieNode } from "../util/fileTrie" import OverflowListFactory from "./OverflowList" import { concatenateResources } from "../util/resources" type OrderEntries = "sort" | "filter" | "map" 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", folderClickBehavior: "link", useSavedState: true, mapFn: (node) => { return node }, sortFn: (a, b) => { // Sort order: folders first, then files. Sort folders and files alphabeticall if ((!a.isFolder && !b.isFolder) || (a.isFolder && b.isFolder)) { // 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 return a.displayName.localeCompare(b.displayName, undefined, { numeric: true, sensitivity: "base", }) } if (!a.isFolder && b.isFolder) { return 1 } else { return -1 } }, filterFn: (node) => node.slugSegment !== "tags", order: ["filter", "map", "sort"], } export type FolderState = { path: string collapsed: boolean } let numExplorers = 0 export default ((userOpts?: Partial) => { const opts: Options = { ...defaultOptions, ...userOpts } const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory() const Explorer: QuartzComponent = ({ cfg, displayClass }: QuartzComponentProps) => { const id = `explorer-${numExplorers++}` return (
    ) } Explorer.css = style Explorer.afterDOMLoaded = concatenateResources(script, overflowListAfterDOMLoaded) return Explorer }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Flex.tsx ================================================ import { concatenateResources } from "../util/resources" import { classNames } from "../util/lang" 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 (
    {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 (
    ) })}
    ) } 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 ================================================ FILE: quartz/components/Footer.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import style from "./styles/footer.scss" import { version } from "../../package.json" import { i18n } from "../i18n" interface Options { links: Record } export default ((opts?: Options) => { const Footer: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => { const year = new Date().getFullYear() const links = opts?.links ?? [] return (

    {i18n(cfg.locale).components.footer.createdWith}{" "} Quartz v{version} © {year}

      {Object.entries(links).map(([text, link]) => (
    • {text}
    • ))}
    ) } Footer.css = style return Footer }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Graph.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" // @ts-ignore import script from "./scripts/graph.inline" import style from "./styles/graph.scss" import { i18n } from "../i18n" import { classNames } from "../util/lang" export interface D3Config { drag: boolean zoom: boolean depth: number scale: number repelForce: number centerForce: number linkDistance: number fontSize: number opacityScale: number removeTags: string[] showTags: boolean focusOnHover?: boolean enableRadial?: boolean } interface GraphOptions { localGraph: Partial | undefined globalGraph: Partial | undefined } const defaultOptions: GraphOptions = { localGraph: { drag: true, zoom: true, depth: 1, scale: 1.1, repelForce: 0.5, centerForce: 0.3, linkDistance: 30, fontSize: 0.6, opacityScale: 1, showTags: true, removeTags: [], focusOnHover: false, enableRadial: false, }, globalGraph: { drag: true, zoom: true, depth: -1, scale: 0.9, repelForce: 0.5, centerForce: 0.2, linkDistance: 30, fontSize: 0.6, opacityScale: 1, showTags: true, removeTags: [], focusOnHover: true, enableRadial: true, }, } export default ((opts?: Partial) => { const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => { const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph } const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph } return (

    {i18n(cfg.locale).components.graph.title}

    ) } Graph.css = style Graph.afterDOMLoaded = script return Graph }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Head.tsx ================================================ import { i18n } from "../i18n" import { FullSlug, getFileExtension, joinSegments, pathToRoot } from "../util/path" import { CSSResourceToStyleElement, JSResourceToScriptElement } from "../util/resources" import { googleFontHref, googleFontSubsetHref } from "../util/theme" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { unescapeHTML } from "../util/escape" import { CustomOgImagesEmitterName } from "../plugins/emitters/ogImage" export default (() => { const Head: QuartzComponent = ({ cfg, fileData, externalResources, ctx, }: QuartzComponentProps) => { const titleSuffix = cfg.pageTitleSuffix ?? "" const title = (fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title) + titleSuffix const description = fileData.frontmatter?.socialDescription ?? 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 path = url.pathname as FullSlug const baseDir = fileData.slug === "404" ? path : pathToRoot(fileData.slug!) const iconPath = joinSegments(baseDir, "static/icon.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 ( {title} {cfg.theme.cdnCaching && cfg.theme.fontOrigin === "googleFonts" && ( <> {cfg.theme.typography.title && ( )} )} {!usesCustomOgImage && ( <> )} {cfg.baseUrl && ( <> )} {css.map((resource) => CSSResourceToStyleElement(resource, true))} {js .filter((resource) => resource.loadTime === "beforeDOMReady") .map((res) => JSResourceToScriptElement(res, true))} {additionalHead.map((resource) => { if (typeof resource === "function") { return resource(fileData) } else { return resource } })} ) } return Head }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Header.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" const Header: QuartzComponent = ({ children }: QuartzComponentProps) => { return children.length > 0 ?
    {children}
    : null } Header.css = ` header { display: flex; flex-direction: row; align-items: center; margin: 2rem 0; gap: 1.5rem; } header h1 { margin: 0; flex: auto; } ` export default (() => Header) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/MobileOnly.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" export default ((component: QuartzComponent) => { const Component = component const MobileOnly: QuartzComponent = (props: QuartzComponentProps) => { return } MobileOnly.displayName = component.displayName MobileOnly.afterDOMLoaded = component?.afterDOMLoaded MobileOnly.beforeDOMLoaded = component?.beforeDOMLoaded MobileOnly.css = component?.css return MobileOnly }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/OverflowList.tsx ================================================ import { JSX } from "preact" const OverflowList = ({ children, ...props }: JSX.HTMLAttributes & { id: string }) => { return (
      {children}
    ) } let numLists = 0 export default () => { const id = `list-${numLists++}` return { OverflowList: (props: JSX.HTMLAttributes) => ( ), 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()) }) `, } } ================================================ FILE: quartz/components/PageList.tsx ================================================ import { FullSlug, isFolderPath, resolveRelative } from "../util/path" import { QuartzPluginData } from "../plugins/vfile" import { Date, getDate } from "./Date" import { QuartzComponent, QuartzComponentProps } from "./types" import { GlobalConfiguration } from "../cfg" export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn { 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) { // 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) } } type Props = { limit?: number sort?: SortFn } & QuartzComponentProps export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => { const sorter = sort ?? byDateAndAlphabeticalFolderFirst(cfg) let list = allFiles.sort(sorter) if (limit) { list = list.slice(0, limit) } return (
      {list.map((page) => { const title = page.frontmatter?.title const tags = page.frontmatter?.tags ?? [] return (
    • {page.dates && }

    • ) })}
    ) } PageList.css = ` .section h3 { margin: 0; } .section > .tags { margin: 0; } ` ================================================ FILE: quartz/components/PageTitle.tsx ================================================ import { pathToRoot } from "../util/path" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { classNames } from "../util/lang" import { i18n } from "../i18n" const PageTitle: QuartzComponent = ({ fileData, cfg, displayClass }: QuartzComponentProps) => { const title = cfg?.pageTitle ?? i18n(cfg.locale).propertyDefaults.title const baseDir = pathToRoot(fileData.slug!) return (

    {title}

    ) } PageTitle.css = ` .page-title { font-size: 1.75rem; margin: 0; font-family: var(--titleFont); } ` export default (() => PageTitle) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/ReaderMode.tsx ================================================ // @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 ( ) } ReaderMode.beforeDOMLoaded = readerModeScript ReaderMode.css = styles export default (() => ReaderMode) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/RecentNotes.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { FullSlug, SimpleSlug, resolveRelative } from "../util/path" import { QuartzPluginData } from "../plugins/vfile" import { byDateAndAlphabetical } from "./PageList" import style from "./styles/recentNotes.scss" import { Date, getDate } from "./Date" import { GlobalConfiguration } from "../cfg" import { i18n } from "../i18n" import { classNames } from "../util/lang" interface Options { title?: string limit: number linkToMore: SimpleSlug | false showTags: boolean filter: (f: QuartzPluginData) => boolean sort: (f1: QuartzPluginData, f2: QuartzPluginData) => number } const defaultOptions = (cfg: GlobalConfiguration): Options => ({ limit: 3, linkToMore: false, showTags: true, filter: () => true, sort: byDateAndAlphabetical(cfg), }) export default ((userOpts?: Partial) => { const RecentNotes: QuartzComponent = ({ allFiles, fileData, displayClass, cfg, }: QuartzComponentProps) => { const opts = { ...defaultOptions(cfg), ...userOpts } const pages = allFiles.filter(opts.filter).sort(opts.sort) const remaining = Math.max(0, pages.length - opts.limit) return (

    {opts.title ?? i18n(cfg.locale).components.recentNotes.title}

      {pages.slice(0, opts.limit).map((page) => { const title = page.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title const tags = page.frontmatter?.tags ?? [] return (
    • {page.dates && (

      )} {opts.showTags && ( )}
    • ) })}
    {opts.linkToMore && remaining > 0 && (

    {i18n(cfg.locale).components.recentNotes.seeRemainingMore({ remaining })}

    )}
    ) } RecentNotes.css = style return RecentNotes }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Search.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import style from "./styles/search.scss" // @ts-ignore import script from "./scripts/search.inline" import { classNames } from "../util/lang" import { i18n } from "../i18n" export interface SearchOptions { enablePreview: boolean } const defaultOptions: SearchOptions = { enablePreview: true, } export default ((userOpts?: Partial) => { const Search: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => { const opts = { ...defaultOptions, ...userOpts } const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder return (
    ) } Search.afterDOMLoaded = script Search.css = style return Search }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/Spacer.tsx ================================================ import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import { classNames } from "../util/lang" function Spacer({ displayClass }: QuartzComponentProps) { return
    } export default (() => Spacer) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/TableOfContents.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import legacyStyle from "./styles/legacyToc.scss" import modernStyle from "./styles/toc.scss" import { classNames } from "../util/lang" // @ts-ignore import script from "./scripts/toc.inline" import { i18n } from "../i18n" import OverflowListFactory from "./OverflowList" import { concatenateResources } from "../util/resources" interface Options { layout: "modern" | "legacy" } const defaultOptions: Options = { layout: "modern", } let numTocs = 0 export default ((opts?: Partial) => { const layout = opts?.layout ?? defaultOptions.layout const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory() const TableOfContents: QuartzComponent = ({ fileData, displayClass, cfg, }: QuartzComponentProps) => { if (!fileData.toc) { return null } const id = `toc-${numTocs++}` return (
    {fileData.toc.map((tocEntry) => (
  • {tocEntry.text}
  • ))}
    ) } TableOfContents.css = modernStyle TableOfContents.afterDOMLoaded = concatenateResources(script, overflowListAfterDOMLoaded) const LegacyTableOfContents: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => { if (!fileData.toc) { return null } return (

    {i18n(cfg.locale).components.tableOfContents.title}

    ) } LegacyTableOfContents.css = legacyStyle return layout === "modern" ? TableOfContents : LegacyTableOfContents }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/TagList.tsx ================================================ import { FullSlug, resolveRelative } from "../util/path" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { classNames } from "../util/lang" const TagList: QuartzComponent = ({ fileData, displayClass }: QuartzComponentProps) => { const tags = fileData.frontmatter?.tags if (tags && tags.length > 0) { return (
      {tags.map((tag) => { const linkDest = resolveRelative(fileData.slug!, `tags/${tag}` as FullSlug) return (
    • {tag}
    • ) })}
    ) } else { return null } } TagList.css = ` .tags { list-style: none; display: flex; padding-left: 0; gap: 0.4rem; margin: 1rem 0; flex-wrap: wrap; } .section-li > .section > .tags { justify-content: flex-end; } .tags > li { display: inline-block; white-space: nowrap; margin: 0; overflow-wrap: normal; } a.internal.tag-link { border-radius: 8px; background-color: var(--highlight); padding: 0.2rem 0.4rem; margin: 0 0.1rem; } ` export default (() => TagList) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/index.ts ================================================ import Content from "./pages/Content" import TagContent from "./pages/TagContent" import FolderContent from "./pages/FolderContent" import NotFound from "./pages/404" import ArticleTitle from "./ArticleTitle" import Darkmode from "./Darkmode" import ReaderMode from "./ReaderMode" import Head from "./Head" import PageTitle from "./PageTitle" import ContentMeta from "./ContentMeta" import Spacer from "./Spacer" import TableOfContents from "./TableOfContents" import Explorer from "./Explorer" import TagList from "./TagList" import Graph from "./Graph" import Backlinks from "./Backlinks" import Search from "./Search" import Footer from "./Footer" import DesktopOnly from "./DesktopOnly" import MobileOnly from "./MobileOnly" import RecentNotes from "./RecentNotes" import Breadcrumbs from "./Breadcrumbs" import Comments from "./Comments" import Flex from "./Flex" import ConditionalRender from "./ConditionalRender" export { ArticleTitle, Content, TagContent, FolderContent, Darkmode, ReaderMode, Head, PageTitle, ContentMeta, Spacer, TableOfContents, Explorer, TagList, Graph, Backlinks, Search, Footer, DesktopOnly, MobileOnly, RecentNotes, NotFound, Breadcrumbs, Comments, Flex, ConditionalRender, } ================================================ FILE: quartz/components/pages/404.tsx ================================================ import { i18n } from "../../i18n" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => { // If baseUrl contains a pathname after the domain, use this as the home link const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) const baseDir = url.pathname return ( ) } export default (() => NotFound) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/pages/Content.tsx ================================================ import { ComponentChildren } from "preact" import { htmlToJsx } from "../../util/jsx" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" const Content: QuartzComponent = ({ fileData, tree }: QuartzComponentProps) => { const content = htmlToJsx(fileData.filePath!, tree) as ComponentChildren const classes: string[] = fileData.frontmatter?.cssclasses ?? [] const classString = ["popover-hint", ...classes].join(" ") return
    {content}
    } export default (() => Content) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/pages/FolderContent.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" import style from "../styles/listPage.scss" import { PageList, SortFn } from "../PageList" import { Root } from "hast" import { htmlToJsx } from "../../util/jsx" 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 { /** * Whether to display number of folders */ showFolderCount: boolean showSubfolders: boolean sort?: SortFn } const defaultOptions: FolderContentOptions = { showFolderCount: true, showSubfolders: true, } export default ((opts?: Partial) => { const options: FolderContentOptions = { ...defaultOptions, ...opts } const FolderContent: QuartzComponent = (props: QuartzComponentProps) => { const { tree, fileData, allFiles, cfg } = props const trie = (props.ctx.trie ??= trieFromAllFiles(allFiles)) const folder = trie.findNode(fileData.slug!.split("/")) if (!folder) { return null } 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 classes = cssClasses.join(" ") const listProps = { ...props, sort: options.sort, allFiles: allPagesInFolder, } const content = ( (tree as Root).children.length === 0 ? fileData.description : htmlToJsx(fileData.filePath!, tree) ) as ComponentChildren return (
    {content}
    {options.showFolderCount && (

    {i18n(cfg.locale).pages.folderContent.itemsUnderFolder({ count: allPagesInFolder.length, })}

    )}
    ) } FolderContent.css = concatenateResources(style, PageList.css) return FolderContent }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/pages/TagContent.tsx ================================================ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" import style from "../styles/listPage.scss" import { PageList, SortFn } from "../PageList" import { FullSlug, getAllSegmentPrefixes, resolveRelative, simplifySlug } from "../../util/path" import { QuartzPluginData } from "../../plugins/vfile" import { Root } from "hast" import { htmlToJsx } from "../../util/jsx" import { i18n } from "../../i18n" import { ComponentChildren } from "preact" import { concatenateResources } from "../../util/resources" interface TagContentOptions { sort?: SortFn numPages: number } const defaultOptions: TagContentOptions = { numPages: 10, } export default ((opts?: Partial) => { const options: TagContentOptions = { ...defaultOptions, ...opts } const TagContent: QuartzComponent = (props: QuartzComponentProps) => { const { tree, fileData, allFiles, cfg } = props const slug = fileData.slug if (!(slug?.startsWith("tags/") || slug === "tags")) { throw new Error(`Component "TagContent" tried to render a non-tag page: ${slug}`) } const tag = simplifySlug(slug.slice("tags/".length) as FullSlug) const allPagesWithTag = (tag: string) => allFiles.filter((file) => (file.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes).includes(tag), ) const content = ( (tree as Root).children.length === 0 ? fileData.description : htmlToJsx(fileData.filePath!, tree) ) as ComponentChildren const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? [] const classes = cssClasses.join(" ") if (tag === "/") { const tags = [ ...new Set( allFiles.flatMap((data) => data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes), ), ].sort((a, b) => a.localeCompare(b)) const tagItemMap: Map = new Map() for (const tag of tags) { tagItemMap.set(tag, allPagesWithTag(tag)) } return (

    {content}

    {i18n(cfg.locale).pages.tagContent.totalTags({ count: tags.length })}

    {tags.map((tag) => { const pages = tagItemMap.get(tag)! const listProps = { ...props, allFiles: pages, } const contentPage = allFiles.filter((file) => file.slug === `tags/${tag}`).at(0) const root = contentPage?.htmlAst const content = !root || root?.children.length === 0 ? contentPage?.description : htmlToJsx(contentPage.filePath!, root) const tagListingPage = `/tags/${tag}` as FullSlug const href = resolveRelative(fileData.slug!, tagListingPage) return (

    {tag}

    {content &&

    {content}

    }

    {i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })} {pages.length > options.numPages && ( <> {" "} {i18n(cfg.locale).pages.tagContent.showingFirst({ count: options.numPages, })} )}

    ) })}
    ) } else { const pages = allPagesWithTag(tag) const listProps = { ...props, allFiles: pages, } return (
    {content}

    {i18n(cfg.locale).pages.tagContent.itemsUnderTag({ count: pages.length })}

    ) } } TagContent.css = concatenateResources(style, PageList.css) return TagContent }) satisfies QuartzComponentConstructor ================================================ FILE: quartz/components/renderPage.tsx ================================================ import { render } from "preact-render-to-string" import { QuartzComponent, QuartzComponentProps } from "./types" import HeaderConstructor from "./Header" import BodyConstructor from "./Body" import { JSResourceToScriptElement, StaticResources } from "../util/resources" import { FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path" import { clone } from "../util/clone" import { visit } from "unist-util-visit" import { Root, Element, ElementContent } from "hast" import { GlobalConfiguration } from "../cfg" import { i18n } from "../i18n" import { styleText } from "util" interface RenderComponents { head: QuartzComponent header: QuartzComponent[] beforeBody: QuartzComponent[] pageBody: QuartzComponent afterBody: QuartzComponent[] left: QuartzComponent[] right: QuartzComponent[] footer: QuartzComponent } const headerRegex = new RegExp(/h[1-6]/) export function pageResources( baseDir: FullSlug | RelativeURL, staticResources: StaticResources, ): StaticResources { const contentIndexPath = joinSegments(baseDir, "static/contentIndex.json") const contentIndexScript = `const fetchData = fetch("${contentIndexPath}").then(data => data.json())` const resources: StaticResources = { css: [ { content: joinSegments(baseDir, "index.css"), }, ...staticResources.css, ], js: [ { src: joinSegments(baseDir, "prescript.js"), loadTime: "beforeDOMReady", contentType: "external", }, { loadTime: "beforeDOMReady", contentType: "inline", spaPreserve: true, script: contentIndexScript, }, ...staticResources.js, ], additionalHead: staticResources.additionalHead, } resources.js.push({ src: joinSegments(baseDir, "postscript.js"), loadTime: "afterDOMReady", moduleType: "module", contentType: "external", }) return resources } function renderTranscludes( root: Root, cfg: GlobalConfiguration, slug: FullSlug, componentData: QuartzComponentProps, visited: Set, ) { // process transcludes in componentData visit(root, "element", (node, _index, _parent) => { if (node.tagName === "blockquote") { const classNames = (node.properties?.className ?? []) as string[] if (classNames.includes("transclude")) { const inner = node.children[0] as Element const transcludeTarget = (inner.properties["data-slug"] ?? slug) as FullSlug if (visited.has(transcludeTarget)) { console.warn( styleText( "yellow", `Warning: Skipping circular transclusion: ${slug} -> ${transcludeTarget}`, ), ) node.children = [ { type: "element", tagName: "p", properties: { style: "color: var(--secondary);" }, children: [ { type: "text", value: `Circular transclusion detected: ${transcludeTarget}`, }, ], }, ] return } visited.add(transcludeTarget) const page = componentData.allFiles.find((f) => f.slug === transcludeTarget) if (!page) { return } let blockRef = node.properties.dataBlock as string | undefined if (blockRef?.startsWith("#^")) { // block transclude blockRef = blockRef.slice("#^".length) let blockNode = page.blocks?.[blockRef] if (blockNode) { if (blockNode.tagName === "li") { blockNode = { type: "element", tagName: "ul", properties: {}, children: [blockNode], } } node.children = [ normalizeHastElement(blockNode, slug, transcludeTarget), { type: "element", tagName: "a", properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] }, children: [ { type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal }, ], }, ] } } else if (blockRef?.startsWith("#") && page.htmlAst) { // header transclude blockRef = blockRef.slice(1) let startIdx = undefined let startDepth = undefined let endIdx = undefined for (const [i, el] of page.htmlAst.children.entries()) { // skip non-headers if (!(el.type === "element" && el.tagName.match(headerRegex))) continue const depth = Number(el.tagName.substring(1)) // lookin for our blockref if (startIdx === undefined || startDepth === undefined) { // skip until we find the blockref that matches if (el.properties?.id === blockRef) { startIdx = i startDepth = depth } } else if (depth <= startDepth) { // looking for new header that is same level or higher endIdx = i break } } if (startIdx === undefined) { return } node.children = [ ...(page.htmlAst.children.slice(startIdx, endIdx) as ElementContent[]).map((child) => normalizeHastElement(child as Element, slug, transcludeTarget), ), { type: "element", tagName: "a", properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] }, children: [ { type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal }, ], }, ] } else if (page.htmlAst) { // page transclude node.children = [ { type: "element", tagName: "h1", properties: {}, children: [ { type: "text", value: page.frontmatter?.title ?? i18n(cfg.locale).components.transcludes.transcludeOf({ targetSlug: page.slug!, }), }, ], }, ...(page.htmlAst.children as ElementContent[]).map((child) => normalizeHastElement(child as Element, slug, transcludeTarget), ), { type: "element", tagName: "a", properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] }, children: [ { type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal }, ], }, ] } } } }) } 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 const visited = new Set([slug]) renderTranscludes(root, cfg, slug, componentData, visited) // set componentData.tree to the edited html that has transclusions rendered componentData.tree = root const { head: Head, header, beforeBody, pageBody: Content, afterBody, left, right, footer: Footer, } = components const Header = HeaderConstructor() const Body = BodyConstructor() const LeftComponent = ( ) const RightComponent = ( ) const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en" const direction = i18n(cfg.locale).direction ?? "ltr" const doc = (
    {LeftComponent}

    {RightComponent}
    {pageResources.js .filter((resource) => resource.loadTime === "afterDOMReady") .map((res) => JSResourceToScriptElement(res, true))} ) return "\n" + render(doc) } ================================================ FILE: quartz/components/scripts/callout.inline.ts ================================================ function toggleCallout(this: HTMLElement) { const outerBlock = this.parentElement! outerBlock.classList.toggle("is-collapsed") const content = outerBlock.getElementsByClassName("callout-content")[0] as HTMLElement if (!content) return const collapsed = outerBlock.classList.contains("is-collapsed") content.style.gridTemplateRows = collapsed ? "0fr" : "1fr" } function setupCallout() { const collapsible = document.getElementsByClassName( `callout is-collapsible`, ) as HTMLCollectionOf for (const div of collapsible) { const title = div.getElementsByClassName("callout-title")[0] as HTMLElement const content = div.getElementsByClassName("callout-content")[0] as HTMLElement if (!title || !content) continue title.addEventListener("click", toggleCallout) window.addCleanup(() => title.removeEventListener("click", toggleCallout)) const collapsed = div.classList.contains("is-collapsed") content.style.gridTemplateRows = collapsed ? "0fr" : "1fr" } } document.addEventListener("nav", setupCallout) ================================================ FILE: quartz/components/scripts/checkbox.inline.ts ================================================ import { getFullSlug } from "../../util/path" const checkboxId = (index: number) => `${getFullSlug(window)}-checkbox-${index}` document.addEventListener("nav", () => { const checkboxes = document.querySelectorAll( "input.checkbox-toggle", ) as NodeListOf checkboxes.forEach((el, index) => { const elId = checkboxId(index) const switchState = (e: Event) => { const newCheckboxState = (e.target as HTMLInputElement)?.checked ? "true" : "false" localStorage.setItem(elId, newCheckboxState) } el.addEventListener("change", switchState) window.addCleanup(() => el.removeEventListener("change", switchState)) if (localStorage.getItem(elId) === "true") { el.checked = true } }) }) ================================================ FILE: quartz/components/scripts/clipboard.inline.ts ================================================ const svgCopy = '' const svgCheck = '' document.addEventListener("nav", () => { const els = document.getElementsByTagName("pre") for (let i = 0; i < els.length; i++) { const codeBlock = els[i].getElementsByTagName("code")[0] if (codeBlock) { const source = ( codeBlock.dataset.clipboard ? JSON.parse(codeBlock.dataset.clipboard) : codeBlock.innerText ).replace(/\n\n/g, "\n") const button = document.createElement("button") button.className = "clipboard-button" button.type = "button" button.innerHTML = svgCopy button.ariaLabel = "Copy source" function onClick() { navigator.clipboard.writeText(source).then( () => { button.blur() button.innerHTML = svgCheck setTimeout(() => { button.innerHTML = svgCopy button.style.borderColor = "" }, 2000) }, (error) => console.error(error), ) } button.addEventListener("click", onClick) window.addCleanup(() => button.removeEventListener("click", onClick)) els[i].prepend(button) } } }) ================================================ FILE: quartz/components/scripts/comments.inline.ts ================================================ const changeTheme = (e: CustomEventMap["themechange"]) => { const theme = e.detail.theme const iframe = document.querySelector("iframe.giscus-frame") as HTMLIFrameElement if (!iframe) { return } if (!iframe.contentWindow) { return } iframe.contentWindow.postMessage( { giscus: { setConfig: { theme: getThemeUrl(getThemeName(theme)), }, }, }, "https://giscus.app", ) } 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 & { dataset: DOMStringMap & { repo: `${string}/${string}` repoId: string category: string categoryId: string themeUrl: string lightTheme: string darkTheme: string mapping: "url" | "title" | "og:title" | "specific" | "number" | "pathname" strict: string reactionsEnabled: string inputPosition: "top" | "bottom" lang: string } } document.addEventListener("nav", () => { const giscusContainer = document.querySelector(".giscus") as GiscusElement if (!giscusContainer) { return } const giscusScript = document.createElement("script") giscusScript.src = "https://giscus.app/client.js" giscusScript.async = true giscusScript.crossOrigin = "anonymous" giscusScript.setAttribute("data-loading", "lazy") giscusScript.setAttribute("data-emit-metadata", "0") giscusScript.setAttribute("data-repo", giscusContainer.dataset.repo) giscusScript.setAttribute("data-repo-id", giscusContainer.dataset.repoId) giscusScript.setAttribute("data-category", giscusContainer.dataset.category) giscusScript.setAttribute("data-category-id", giscusContainer.dataset.categoryId) giscusScript.setAttribute("data-mapping", giscusContainer.dataset.mapping) giscusScript.setAttribute("data-strict", giscusContainer.dataset.strict) giscusScript.setAttribute("data-reactions-enabled", giscusContainer.dataset.reactionsEnabled) giscusScript.setAttribute("data-input-position", giscusContainer.dataset.inputPosition) giscusScript.setAttribute("data-lang", giscusContainer.dataset.lang) const theme = document.documentElement.getAttribute("saved-theme") if (theme) { giscusScript.setAttribute("data-theme", getThemeUrl(getThemeName(theme))) } giscusContainer.appendChild(giscusScript) document.addEventListener("themechange", changeTheme) window.addCleanup(() => document.removeEventListener("themechange", changeTheme)) }) ================================================ FILE: quartz/components/scripts/darkmode.inline.ts ================================================ const userPref = window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark" const currentTheme = localStorage.getItem("theme") ?? userPref document.documentElement.setAttribute("saved-theme", currentTheme) const emitThemeChangeEvent = (theme: "light" | "dark") => { const event: CustomEventMap["themechange"] = new CustomEvent("themechange", { detail: { theme }, }) document.dispatchEvent(event) } document.addEventListener("nav", () => { const switchTheme = () => { const newTheme = document.documentElement.getAttribute("saved-theme") === "dark" ? "light" : "dark" document.documentElement.setAttribute("saved-theme", newTheme) localStorage.setItem("theme", newTheme) emitThemeChangeEvent(newTheme) } const themeChange = (e: MediaQueryListEvent) => { const newTheme = e.matches ? "dark" : "light" document.documentElement.setAttribute("saved-theme", newTheme) localStorage.setItem("theme", newTheme) emitThemeChangeEvent(newTheme) } for (const darkmodeButton of document.getElementsByClassName("darkmode")) { darkmodeButton.addEventListener("click", switchTheme) window.addCleanup(() => darkmodeButton.removeEventListener("click", switchTheme)) } // Listen for changes in prefers-color-scheme const colorSchemeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)") colorSchemeMediaQuery.addEventListener("change", themeChange) window.addCleanup(() => colorSchemeMediaQuery.removeEventListener("change", themeChange)) }) ================================================ FILE: quartz/components/scripts/explorer.inline.ts ================================================ import { FileTrieNode } from "../../util/fileTrie" import { FullSlug, resolveRelative, simplifySlug } from "../../util/path" import { ContentDetails } from "../../plugins/emitters/contentIndex" type MaybeHTMLElement = HTMLElement | undefined 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 function toggleExplorer(this: HTMLElement) { const nearestExplorer = this.closest(".explorer") as HTMLElement if (!nearestExplorer) return const explorerCollapsed = nearestExplorer.classList.toggle("collapsed") nearestExplorer.setAttribute( "aria-expanded", nearestExplorer.getAttribute("aria-expanded") === "true" ? "false" : "true", ) if (!explorerCollapsed) { // Stop 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) { evt.stopPropagation() const target = evt.target as MaybeHTMLElement if (!target) return // Check if target was svg icon or button const isSvg = target.nodeName === "svg" // corresponding
      element relative to clicked button/folder const folderContainer = ( isSvg ? // svg -> div.folder-container target.parentElement : // button.folder-button -> div -> div.folder-container target.parentElement?.parentElement ) as MaybeHTMLElement if (!folderContainer) return const childFolderContainer = folderContainer.nextElementSibling as MaybeHTMLElement if (!childFolderContainer) return childFolderContainer.classList.toggle("open") // Collapse folder container const isCollapsed = !childFolderContainer.classList.contains("open") 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) localStorage.setItem("fileTree", stringifiedFileTree) } function createFileNode(currentSlug: FullSlug, node: FileTrieNode): HTMLLIElement { const template = document.getElementById("template-file") as HTMLTemplateElement 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 (currentSlug === node.slug) { a.classList.add("active") } return li } function createFolderNode( currentSlug: FullSlug, node: FileTrieNode, 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 const folderPath = node.slug folderContainer.dataset.folderpath = folderPath if (currentSlug === folderPath) { folderContainer.classList.add("active") } 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 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( 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 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 for (const button of folderButtons) { button.addEventListener("click", toggleFolder) window.addCleanup(() => button.removeEventListener("click", toggleFolder)) } } const folderIcons = explorer.getElementsByClassName( "folder-icon", ) as HTMLCollectionOf 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 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 in this edge case. const explorer = document.querySelector(".explorer") if (explorer && !explorer.classList.contains("collapsed")) { document.documentElement.classList.add("mobile-no-scroll") return } }) function setFolderState(folderElement: HTMLElement, collapsed: boolean) { return collapsed ? folderElement.classList.remove("open") : folderElement.classList.add("open") } ================================================ FILE: quartz/components/scripts/graph.inline.ts ================================================ import type { ContentDetails } from "../../plugins/emitters/contentIndex" import { SimulationNodeDatum, SimulationLinkDatum, Simulation, forceSimulation, forceManyBody, forceCenter, forceLink, forceCollide, forceRadial, zoomIdentity, select, drag, zoom, } from "d3" import { Text, Graphics, Application, Container, Circle } from "pixi.js" import { Group as TweenGroup, Tween as Tweened } from "@tweenjs/tween.js" import { registerEscapeHandler, removeAllChildren } from "./util" import { FullSlug, SimpleSlug, getFullSlug, resolveRelative, simplifySlug } from "../../util/path" import { D3Config } from "../Graph" type GraphicsInfo = { color: string gfx: Graphics alpha: number active: boolean } type NodeData = { id: SimpleSlug text: string tags: string[] } & SimulationNodeDatum type SimpleLinkData = { source: SimpleSlug target: SimpleSlug } type LinkData = { source: NodeData target: NodeData } & SimulationLinkDatum type LinkRenderData = GraphicsInfo & { simulationData: LinkData } type NodeRenderData = GraphicsInfo & { simulationData: NodeData label: Text } const localStorageKey = "graph-visited" function getVisited(): Set { return new Set(JSON.parse(localStorage.getItem(localStorageKey) ?? "[]")) } function addToVisited(slug: SimpleSlug) { const visited = getVisited() visited.add(slug) localStorage.setItem(localStorageKey, JSON.stringify([...visited])) } type TweenNode = { update: (time: number) => void stop: () => void } async function renderGraph(graph: HTMLElement, fullSlug: FullSlug) { const slug = simplifySlug(fullSlug) const visited = getVisited() removeAllChildren(graph) let { drag: enableDrag, zoom: enableZoom, depth, scale, repelForce, centerForce, linkDistance, fontSize, opacityScale, removeTags, showTags, focusOnHover, enableRadial, } = JSON.parse(graph.dataset["cfg"]!) as D3Config const data: Map = new Map( Object.entries(await fetchData).map(([k, v]) => [ simplifySlug(k as FullSlug), v, ]), ) const links: SimpleLinkData[] = [] const tags: SimpleSlug[] = [] const validLinks = new Set(data.keys()) const tweens = new Map() for (const [source, details] of data.entries()) { const outgoing = details.links ?? [] for (const dest of outgoing) { if (validLinks.has(dest)) { links.push({ source: source, target: dest }) } } if (showTags) { const localTags = details.tags .filter((tag) => !removeTags.includes(tag)) .map((tag) => simplifySlug(("tags/" + tag) as FullSlug)) tags.push(...localTags.filter((tag) => !tags.includes(tag))) for (const tag of localTags) { links.push({ source: source, target: tag }) } } } const neighbourhood = new Set() const wl: (SimpleSlug | "__SENTINEL")[] = [slug, "__SENTINEL"] if (depth >= 0) { while (depth >= 0 && wl.length > 0) { // compute neighbours const cur = wl.shift()! if (cur === "__SENTINEL") { depth-- wl.push("__SENTINEL") } else { neighbourhood.add(cur) const outgoing = links.filter((l) => l.source === cur) const incoming = links.filter((l) => l.target === cur) wl.push(...outgoing.map((l) => l.target), ...incoming.map((l) => l.source)) } } } else { validLinks.forEach((id) => neighbourhood.add(id)) if (showTags) tags.forEach((tag) => neighbourhood.add(tag)) } const nodes = [...neighbourhood].map((url) => { const text = url.startsWith("tags/") ? "#" + url.substring(5) : (data.get(url)?.title ?? url) return { id: url, text, tags: data.get(url)?.tags ?? [], } }) const graphData: { nodes: NodeData[]; links: LinkData[] } = { nodes, links: links .filter((l) => neighbourhood.has(l.source) && neighbourhood.has(l.target)) .map((l) => ({ source: nodes.find((n) => n.id === l.source)!, target: nodes.find((n) => n.id === l.target)!, })), } const width = graph.offsetWidth const height = Math.max(graph.offsetHeight, 250) // we virtualize the simulation and use pixi to actually render it const simulation: Simulation = forceSimulation(graphData.nodes) .force("charge", forceManyBody().strength(-100 * repelForce)) .force("center", forceCenter().strength(centerForce)) .force("link", forceLink(graphData.links).distance(linkDistance)) .force("collide", forceCollide((n) => nodeRadius(n)).iterations(3)) const radius = (Math.min(width, height) / 2) * 0.8 if (enableRadial) simulation.force("radial", forceRadial(radius).strength(0.2)) // precompute style prop strings as pixi doesn't support css variables const cssVars = [ "--secondary", "--tertiary", "--gray", "--light", "--lightgray", "--dark", "--darkgray", "--bodyFont", ] as const const computedStyleMap = cssVars.reduce( (acc, key) => { acc[key] = getComputedStyle(document.documentElement).getPropertyValue(key) return acc }, {} as Record<(typeof cssVars)[number], string>, ) // calculate color const color = (d: NodeData) => { const isCurrent = d.id === slug if (isCurrent) { return computedStyleMap["--secondary"] } else if (visited.has(d.id) || d.id.startsWith("tags/")) { return computedStyleMap["--tertiary"] } else { return computedStyleMap["--gray"] } } function nodeRadius(d: NodeData) { const numLinks = graphData.links.filter( (l) => l.source.id === d.id || l.target.id === d.id, ).length return 2 + Math.sqrt(numLinks) } let hoveredNodeId: string | null = null let hoveredNeighbours: Set = new Set() const linkRenderData: LinkRenderData[] = [] const nodeRenderData: NodeRenderData[] = [] function updateHoverInfo(newHoveredId: string | null) { hoveredNodeId = newHoveredId if (newHoveredId === null) { hoveredNeighbours = new Set() for (const n of nodeRenderData) { n.active = false } for (const l of linkRenderData) { l.active = false } } else { hoveredNeighbours = new Set() for (const l of linkRenderData) { const linkData = l.simulationData if (linkData.source.id === newHoveredId || linkData.target.id === newHoveredId) { hoveredNeighbours.add(linkData.source.id) hoveredNeighbours.add(linkData.target.id) } l.active = linkData.source.id === newHoveredId || linkData.target.id === newHoveredId } for (const n of nodeRenderData) { n.active = hoveredNeighbours.has(n.simulationData.id) } } } let dragStartTime = 0 let dragging = false function renderLinks() { tweens.get("link")?.stop() const tweenGroup = new TweenGroup() for (const l of linkRenderData) { let alpha = 1 // if we are hovering over a node, we want to highlight the immediate neighbours // with full alpha and the rest with default alpha if (hoveredNodeId) { alpha = l.active ? 1 : 0.2 } l.color = l.active ? computedStyleMap["--gray"] : computedStyleMap["--lightgray"] tweenGroup.add(new Tweened(l).to({ alpha }, 200)) } tweenGroup.getAll().forEach((tw) => tw.start()) tweens.set("link", { update: tweenGroup.update.bind(tweenGroup), stop() { tweenGroup.getAll().forEach((tw) => tw.stop()) }, }) } function renderLabels() { tweens.get("label")?.stop() const tweenGroup = new TweenGroup() const defaultScale = 1 / scale const activeScale = defaultScale * 1.1 for (const n of nodeRenderData) { const nodeId = n.simulationData.id if (hoveredNodeId === nodeId) { tweenGroup.add( new Tweened(n.label).to( { alpha: 1, scale: { x: activeScale, y: activeScale }, }, 100, ), ) } else { tweenGroup.add( new Tweened(n.label).to( { alpha: n.label.alpha, scale: { x: defaultScale, y: defaultScale }, }, 100, ), ) } } tweenGroup.getAll().forEach((tw) => tw.start()) tweens.set("label", { update: tweenGroup.update.bind(tweenGroup), stop() { tweenGroup.getAll().forEach((tw) => tw.stop()) }, }) } function renderNodes() { tweens.get("hover")?.stop() const tweenGroup = new TweenGroup() for (const n of nodeRenderData) { let alpha = 1 // if we are hovering over a node, we want to highlight the immediate neighbours if (hoveredNodeId !== null && focusOnHover) { alpha = n.active ? 1 : 0.2 } tweenGroup.add(new Tweened(n.gfx, tweenGroup).to({ alpha }, 200)) } tweenGroup.getAll().forEach((tw) => tw.start()) tweens.set("hover", { update: tweenGroup.update.bind(tweenGroup), stop() { tweenGroup.getAll().forEach((tw) => tw.stop()) }, }) } function renderPixiFromD3() { renderNodes() renderLinks() renderLabels() } tweens.forEach((tween) => tween.stop()) tweens.clear() const app = new Application() await app.init({ width, height, antialias: true, autoStart: false, autoDensity: true, backgroundAlpha: 0, preference: "webgpu", resolution: window.devicePixelRatio, eventMode: "static", }) graph.appendChild(app.canvas) const stage = app.stage stage.interactive = false const labelsContainer = new Container({ zIndex: 3, isRenderGroup: true }) const nodesContainer = new Container({ zIndex: 2, isRenderGroup: true }) const linkContainer = new Container({ zIndex: 1, isRenderGroup: true }) stage.addChild(nodesContainer, labelsContainer, linkContainer) for (const n of graphData.nodes) { const nodeId = n.id const label = new Text({ interactive: false, eventMode: "none", text: n.text, alpha: 0, anchor: { x: 0.5, y: 1.2 }, style: { fontSize: fontSize * 15, fill: computedStyleMap["--dark"], fontFamily: computedStyleMap["--bodyFont"], }, resolution: window.devicePixelRatio * 4, }) label.scale.set(1 / scale) let oldLabelOpacity = 0 const isTagNode = nodeId.startsWith("tags/") const gfx = new Graphics({ interactive: true, label: nodeId, eventMode: "static", hitArea: new Circle(0, 0, nodeRadius(n)), cursor: "pointer", }) .circle(0, 0, nodeRadius(n)) .fill({ color: isTagNode ? computedStyleMap["--light"] : color(n) }) .on("pointerover", (e) => { updateHoverInfo(e.target.label) oldLabelOpacity = label.alpha if (!dragging) { renderPixiFromD3() } }) .on("pointerleave", () => { updateHoverInfo(null) label.alpha = oldLabelOpacity if (!dragging) { renderPixiFromD3() } }) if (isTagNode) { gfx.stroke({ width: 2, color: computedStyleMap["--tertiary"] }) } nodesContainer.addChild(gfx) labelsContainer.addChild(label) const nodeRenderDatum: NodeRenderData = { simulationData: n, gfx, label, color: color(n), alpha: 1, active: false, } nodeRenderData.push(nodeRenderDatum) } for (const l of graphData.links) { const gfx = new Graphics({ interactive: false, eventMode: "none" }) linkContainer.addChild(gfx) const linkRenderDatum: LinkRenderData = { simulationData: l, gfx, color: computedStyleMap["--lightgray"], alpha: 1, active: false, } linkRenderData.push(linkRenderDatum) } let currentTransform = zoomIdentity if (enableDrag) { select(app.canvas).call( drag() .container(() => app.canvas) .subject(() => graphData.nodes.find((n) => n.id === hoveredNodeId)) .on("start", function dragstarted(event) { if (!event.active) simulation.alphaTarget(1).restart() event.subject.fx = event.subject.x event.subject.fy = event.subject.y event.subject.__initialDragPos = { x: event.subject.x, y: event.subject.y, fx: event.subject.fx, fy: event.subject.fy, } dragStartTime = Date.now() dragging = true }) .on("drag", function dragged(event) { const initPos = event.subject.__initialDragPos event.subject.fx = initPos.x + (event.x - initPos.x) / currentTransform.k event.subject.fy = initPos.y + (event.y - initPos.y) / currentTransform.k }) .on("end", function dragended(event) { if (!event.active) simulation.alphaTarget(0) event.subject.fx = null event.subject.fy = null dragging = false // if the time between mousedown and mouseup is short, we consider it a click if (Date.now() - dragStartTime < 500) { const node = graphData.nodes.find((n) => n.id === event.subject.id) as NodeData const targ = resolveRelative(fullSlug, node.id) window.spaNavigate(new URL(targ, window.location.toString())) } }), ) } else { for (const node of nodeRenderData) { node.gfx.on("click", () => { const targ = resolveRelative(fullSlug, node.simulationData.id) window.spaNavigate(new URL(targ, window.location.toString())) }) } } if (enableZoom) { select(app.canvas).call( zoom() .extent([ [0, 0], [width, height], ]) .scaleExtent([0.25, 4]) .on("zoom", ({ transform }) => { currentTransform = transform stage.scale.set(transform.k, transform.k) stage.position.set(transform.x, transform.y) // zoom adjusts opacity of labels too const scale = transform.k * opacityScale let scaleOpacity = Math.max((scale - 1) / 3.75, 0) const activeNodes = nodeRenderData.filter((n) => n.active).flatMap((n) => n.label) for (const label of labelsContainer.children) { if (!activeNodes.includes(label)) { label.alpha = scaleOpacity } } }), ) } let stopAnimation = false function animate(time: number) { if (stopAnimation) return for (const n of nodeRenderData) { const { x, y } = n.simulationData if (!x || !y) continue n.gfx.position.set(x + width / 2, y + height / 2) if (n.label) { n.label.position.set(x + width / 2, y + height / 2) } } for (const l of linkRenderData) { const linkData = l.simulationData l.gfx.clear() l.gfx.moveTo(linkData.source.x! + width / 2, linkData.source.y! + height / 2) l.gfx .lineTo(linkData.target.x! + width / 2, linkData.target.y! + height / 2) .stroke({ alpha: l.alpha, width: 1, color: l.color }) } tweens.forEach((t) => t.update(time)) app.renderer.render(stage) requestAnimationFrame(animate) } requestAnimationFrame(animate) 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"]) => { const slug = e.detail.url addToVisited(simplifySlug(slug)) async function renderLocalGraph() { cleanupLocalGraphs() const localGraphContainers = document.getElementsByClassName("graph-container") for (const container of localGraphContainers) { localGraphCleanups.push(await renderGraph(container as HTMLElement, slug)) } } await renderLocalGraph() 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() { cleanupGlobalGraphs() for (const container of containers) { container.classList.remove("active") const sidebar = container.closest(".sidebar") as HTMLElement if (sidebar) { sidebar.style.zIndex = "" } } } async function shortcutHandler(e: HTMLElementEventMap["keydown"]) { if (e.key === "g" && (e.ctrlKey || e.metaKey) && !e.shiftKey) { e.preventDefault() const anyGlobalGraphOpen = containers.some((container) => container.classList.contains("active"), ) anyGlobalGraphOpen ? hideGlobalGraph() : renderGlobalGraph() } } const containerIcons = document.getElementsByClassName("global-graph-icon") Array.from(containerIcons).forEach((icon) => { icon.addEventListener("click", renderGlobalGraph) window.addCleanup(() => icon.removeEventListener("click", renderGlobalGraph)) }) document.addEventListener("keydown", shortcutHandler) window.addCleanup(() => { document.removeEventListener("keydown", shortcutHandler) cleanupLocalGraphs() cleanupGlobalGraphs() }) }) ================================================ FILE: quartz/components/scripts/mermaid.inline.ts ================================================ 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) // Touch drag events const touchStartHandler = this.onTouchStart.bind(this) const touchMoveHandler = this.onTouchMove.bind(this) const touchEndHandler = this.onTouchEnd.bind(this) const resizeHandler = this.resetTransform.bind(this) this.container.addEventListener("mousedown", mouseDownHandler) document.addEventListener("mousemove", mouseMoveHandler) document.addEventListener("mouseup", mouseUpHandler) this.container.addEventListener("touchstart", touchStartHandler, { passive: false }) document.addEventListener("touchmove", touchMoveHandler, { passive: false }) document.addEventListener("touchend", touchEndHandler) window.addEventListener("resize", resizeHandler) this.cleanups.push( () => this.container.removeEventListener("mousedown", mouseDownHandler), () => document.removeEventListener("mousemove", mouseMoveHandler), () => document.removeEventListener("mouseup", mouseUpHandler), () => this.container.removeEventListener("touchstart", touchStartHandler), () => document.removeEventListener("touchmove", touchMoveHandler), () => document.removeEventListener("touchend", touchEndHandler), () => 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 onTouchStart(e: TouchEvent) { if (e.touches.length !== 1) return this.isDragging = true const touch = e.touches[0] this.startPan = { x: touch.clientX - this.currentPan.x, y: touch.clientY - this.currentPan.y } } private onTouchMove(e: TouchEvent) { if (!this.isDragging || e.touches.length !== 1) return e.preventDefault() // Prevent scrolling const touch = e.touches[0] this.currentPan = { x: touch.clientX - this.startPan.x, y: touch.clientY - this.startPan.y, } this.updateTransform() } private onTouchEnd() { this.isDragging = false } 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() { const svg = this.content.querySelector("svg")! const rect = svg.getBoundingClientRect() const width = rect.width / this.scale const height = rect.height / this.scale this.scale = 1 this.currentPan = { x: (this.container.clientWidth - width) / 2, y: (this.container.clientHeight - 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 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 = 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) }) } }) ================================================ FILE: quartz/components/scripts/popover.inline.ts ================================================ import { computePosition, flip, inline, shift } from "@floating-ui/dom" import { normalizeRelativeURLs } from "../../util/path" import { fetchCanonical } from "./util" const p = new DOMParser() let activeAnchor: HTMLAnchorElement | null = null async function mouseEnterHandler( this: HTMLAnchorElement, { clientX, clientY }: { clientX: number; clientY: number }, ) { const link = (activeAnchor = this) if (link.dataset.noPopover === "true") { return } async function setPosition(popoverElement: HTMLElement) { const { x, y } = await computePosition(link, popoverElement, { strategy: "fixed", middleware: [inline({ x: clientX, y: clientY }), shift(), flip()], }) Object.assign(popoverElement.style, { transform: `translate(${x.toFixed()}px, ${y.toFixed()}px)`, }) } function showPopover(popoverElement: HTMLElement) { clearActivePopover() popoverElement.classList.add("active-popover") setPosition(popoverElement as HTMLElement) if (hash !== "") { const targetAnchor = `#popover-internal-${hash.slice(1)}` 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 targetUrl = new URL(link.href) const hash = decodeURIComponent(targetUrl.hash) targetUrl.hash = "" targetUrl.search = "" const popoverId = `popover-${link.pathname}` const prevPopoverElement = document.getElementById(popoverId) // dont refetch if there's already a popover if (!!document.getElementById(popoverId)) { showPopover(prevPopoverElement as HTMLElement) return } const response = await fetchCanonical(targetUrl).catch((err) => { console.error(err) }) if (!response) return const [contentType] = response.headers.get("Content-Type")!.split(";") const [contentTypeCategory, typeInfo] = contentType.split("/") const popoverElement = document.createElement("div") popoverElement.id = popoverId popoverElement.classList.add("popover") const popoverInner = document.createElement("div") popoverInner.classList.add("popover-inner") popoverInner.dataset.contentType = contentType ?? undefined popoverElement.appendChild(popoverInner) switch (contentTypeCategory) { case "image": const img = document.createElement("img") img.src = targetUrl.toString() img.alt = targetUrl.pathname popoverInner.appendChild(img) break case "application": switch (typeInfo) { case "pdf": const pdf = document.createElement("iframe") pdf.src = targetUrl.toString() popoverInner.appendChild(pdf) break default: break } break default: const contents = await response.text() const html = p.parseFromString(contents, "text/html") 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")] if (elts.length === 0) return elts.forEach((elt) => popoverInner.appendChild(elt)) } if (!!document.getElementById(popoverId)) { return } 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", () => { const links = [...document.querySelectorAll("a.internal")] as HTMLAnchorElement[] for (const link of links) { link.addEventListener("mouseenter", mouseEnterHandler) link.addEventListener("mouseleave", clearActivePopover) window.addCleanup(() => { link.removeEventListener("mouseenter", mouseEnterHandler) link.removeEventListener("mouseleave", clearActivePopover) }) } }) ================================================ FILE: quartz/components/scripts/readermode.inline.ts ================================================ 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") }) ================================================ FILE: quartz/components/scripts/search.inline.ts ================================================ import FlexSearch, { DefaultDocumentSearchResults } from "flexsearch" import { ContentDetails } from "../../plugins/emitters/contentIndex" import { registerEscapeHandler, removeAllChildren } from "./util" import { FullSlug, normalizeRelativeURLs, resolveRelative } from "../../util/path" interface Item { id: number slug: FullSlug title: string content: string tags: string[] [key: string]: any } // Can be expanded with things like "term" in the future type SearchType = "basic" | "tags" let searchType: SearchType = "basic" let currentSearchTerm: string = "" const encoder = (str: string): string[] => { const tokens: string[] = [] let bufferStart = -1 let bufferEnd = -1 const lower = str.toLowerCase() let i = 0 for (const char of lower) { const code = char.codePointAt(0)! const isCJK = (code >= 0x3040 && code <= 0x309f) || (code >= 0x30a0 && code <= 0x30ff) || (code >= 0x4e00 && code <= 0x9fff) || (code >= 0xac00 && code <= 0xd7af) || (code >= 0x20000 && code <= 0x2a6df) const isWhitespace = code === 32 || code === 9 || code === 10 || code === 13 if (isCJK) { if (bufferStart !== -1) { tokens.push(lower.slice(bufferStart, bufferEnd)) bufferStart = -1 } tokens.push(char) } else if (isWhitespace) { if (bufferStart !== -1) { tokens.push(lower.slice(bufferStart, bufferEnd)) bufferStart = -1 } } else { if (bufferStart === -1) bufferStart = i bufferEnd = i + char.length } i += char.length } if (bufferStart !== -1) { tokens.push(lower.slice(bufferStart)) } return tokens } let index = new FlexSearch.Document({ encode: encoder, document: { id: "id", tag: "tags", index: [ { field: "title", tokenize: "forward", }, { field: "content", tokenize: "forward", }, { field: "tags", tokenize: "forward", }, ], }, }) const p = new DOMParser() const fetchContentCache: Map = new Map() const contextWindowWords = 30 const numSearchResults = 8 const numTagResults = 5 const tokenizeTerm = (term: string) => { const tokens = term.split(/\s+/).filter((t) => t.trim() !== "") const tokenLen = tokens.length if (tokenLen > 1) { for (let i = 1; i < tokenLen; i++) { tokens.push(tokens.slice(0, i + 1).join(" ")) } } return tokens.sort((a, b) => b.length - a.length) // always highlight longest terms first } function highlight(searchTerm: string, text: string, trim?: boolean) { const tokenizedTerms = tokenizeTerm(searchTerm) let tokenizedText = text.split(/\s+/).filter((t) => t !== "") let startIndex = 0 let endIndex = tokenizedText.length - 1 if (trim) { const includesCheck = (tok: string) => tokenizedTerms.some((term) => tok.toLowerCase().startsWith(term.toLowerCase())) const occurrencesIndices = tokenizedText.map(includesCheck) let bestSum = 0 let bestIndex = 0 for (let i = 0; i < Math.max(tokenizedText.length - contextWindowWords, 0); i++) { const window = occurrencesIndices.slice(i, i + contextWindowWords) const windowSum = window.reduce((total, cur) => total + (cur ? 1 : 0), 0) if (windowSum >= bestSum) { bestSum = windowSum bestIndex = i } } startIndex = Math.max(bestIndex - contextWindowWords, 0) endIndex = Math.min(startIndex + 2 * contextWindowWords, tokenizedText.length - 1) tokenizedText = tokenizedText.slice(startIndex, endIndex) } const slice = tokenizedText .map((tok) => { // see if this tok is prefixed by any search terms for (const searchTok of tokenizedTerms) { if (tok.toLowerCase().includes(searchTok.toLowerCase())) { const regex = new RegExp(searchTok.toLowerCase(), "gi") return tok.replace(regex, `$&`) } } return tok }) .join(" ") return `${startIndex === 0 ? "" : "..."}${slice}${ endIndex === tokenizedText.length - 1 ? "" : "..." }` } function highlightHTML(searchTerm: string, el: HTMLElement) { const p = new DOMParser() const tokenizedTerms = tokenizeTerm(searchTerm) const html = p.parseFromString(el.innerHTML, "text/html") const createHighlightSpan = (text: string) => { const span = document.createElement("span") span.className = "highlight" span.textContent = text return span } const highlightTextNodes = (node: Node, term: string) => { if (node.nodeType === Node.TEXT_NODE) { const nodeText = node.nodeValue ?? "" const regex = new RegExp(term.toLowerCase(), "gi") const matches = nodeText.match(regex) if (!matches || matches.length === 0) return const spanContainer = document.createElement("span") let lastIndex = 0 for (const match of matches) { const matchIndex = nodeText.indexOf(match, lastIndex) spanContainer.appendChild(document.createTextNode(nodeText.slice(lastIndex, matchIndex))) spanContainer.appendChild(createHighlightSpan(match)) lastIndex = matchIndex + match.length } spanContainer.appendChild(document.createTextNode(nodeText.slice(lastIndex))) node.parentNode?.replaceChild(spanContainer, node) } else if (node.nodeType === Node.ELEMENT_NODE) { if ((node as HTMLElement).classList.contains("highlight")) return Array.from(node.childNodes).forEach((child) => highlightTextNodes(child, term)) } } for (const term of tokenizedTerms) { highlightTextNodes(html.body, term) } return html.body } async function setupSearch(searchElement: Element, currentSlug: FullSlug, data: ContentIndex) { const container = searchElement.querySelector(".search-container") as HTMLElement if (!container) return 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) => { searchLayout.appendChild(el) } const enablePreview = searchLayout.dataset.preview === "true" let preview: HTMLDivElement | undefined = undefined let previewInner: HTMLDivElement | undefined = undefined const results = document.createElement("div") results.className = "results-container" appendLayout(results) if (enablePreview) { preview = document.createElement("div") preview.className = "preview-container" appendLayout(preview) } function hideSearch() { container.classList.remove("active") searchBar.value = "" // clear the input when we dismiss the search if (sidebar) sidebar.style.zIndex = "" removeAllChildren(results) if (preview) { removeAllChildren(preview) } searchLayout.classList.remove("display-results") searchType = "basic" // reset search type after closing searchButton.focus() } function showSearch(searchTypeNew: SearchType) { searchType = searchTypeNew if (sidebar) sidebar.style.zIndex = "1" container.classList.add("active") searchBar.focus() } let currentHover: HTMLInputElement | null = null async function shortcutHandler(e: HTMLElementEventMap["keydown"]) { if (e.key === "k" && (e.ctrlKey || e.metaKey) && !e.shiftKey) { e.preventDefault() const searchBarOpen = container.classList.contains("active") searchBarOpen ? hideSearch() : showSearch("basic") return } else if (e.shiftKey && (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") { // Hotkey to open tag search e.preventDefault() const searchBarOpen = container.classList.contains("active") searchBarOpen ? hideSearch() : showSearch("tags") // add "#" prefix for tag search searchBar.value = "#" return } if (currentHover) { currentHover.classList.remove("focus") } // If search is active, then we will render the first result and display accordingly if (!container.classList.contains("active")) return if (e.key === "Enter" && !e.isComposing) { // If result has focus, navigate to that one, otherwise pick first result if (results.contains(document.activeElement)) { const active = document.activeElement as HTMLInputElement if (active.classList.contains("no-match")) return await displayPreview(active) active.click() } else { const anchor = document.getElementsByClassName("result-card")[0] as HTMLInputElement | null if (!anchor || anchor.classList.contains("no-match")) return await displayPreview(anchor) anchor.click() } } else if (e.key === "ArrowUp" || (e.shiftKey && e.key === "Tab")) { e.preventDefault() if (results.contains(document.activeElement)) { // If an element in results-container already has focus, focus previous one const currentResult = currentHover ? currentHover : (document.activeElement as HTMLInputElement | null) const prevResult = currentResult?.previousElementSibling as HTMLInputElement | null currentResult?.classList.remove("focus") prevResult?.focus() if (prevResult) currentHover = prevResult await displayPreview(prevResult) } } else if (e.key === "ArrowDown" || e.key === "Tab") { e.preventDefault() // The results should already been focused, so we need to find the next one. // The activeElement is the search bar, so we need to find the first result and focus it. if (document.activeElement === searchBar || currentHover !== null) { const firstResult = currentHover ? currentHover : (document.getElementsByClassName("result-card")[0] as HTMLInputElement | null) const secondResult = firstResult?.nextElementSibling as HTMLInputElement | null firstResult?.classList.remove("focus") secondResult?.focus() if (secondResult) currentHover = secondResult await displayPreview(secondResult) } } } const formatForDisplay = (term: string, id: number) => { const slug = idDataMap[id] return { id, slug, title: searchType === "tags" ? data[slug].title : highlight(term, data[slug].title ?? ""), content: highlight(term, data[slug].content ?? "", true), tags: highlightTags(term.substring(1), data[slug].tags), } } function highlightTags(term: string, tags: string[]) { if (!tags || searchType !== "tags") { return [] } return tags .map((tag) => { if (tag.toLowerCase().includes(term.toLowerCase())) { return `
    • #${tag}

    • ` } else { return `
    • #${tag}

    • ` } }) .slice(0, numTagResults) } function resolveUrl(slug: FullSlug): URL { return new URL(resolveRelative(currentSlug, slug), location.toString()) } const resultToHTML = ({ slug, title, content, tags }: Item) => { const htmlTags = tags.length > 0 ? `
        ${tags.join("")}
      ` : `` const itemTile = document.createElement("a") itemTile.classList.add("result-card") itemTile.id = slug itemTile.href = resolveUrl(slug).toString() itemTile.innerHTML = `

      ${title}

      ${htmlTags}

      ${content}

      ` itemTile.addEventListener("click", (event) => { if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return hideSearch() }) const handler = (event: MouseEvent) => { if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return hideSearch() } async function onMouseEnter(ev: MouseEvent) { if (!ev.target) return const target = ev.target as HTMLInputElement await displayPreview(target) } itemTile.addEventListener("mouseenter", onMouseEnter) window.addCleanup(() => itemTile.removeEventListener("mouseenter", onMouseEnter)) itemTile.addEventListener("click", handler) window.addCleanup(() => itemTile.removeEventListener("click", handler)) return itemTile } async function displayResults(finalResults: Item[]) { removeAllChildren(results) if (finalResults.length === 0) { results.innerHTML = `

      No results.

      Try another search term?

      ` } else { results.append(...finalResults.map(resultToHTML)) } if (finalResults.length === 0 && preview) { // no results, clear previous preview removeAllChildren(preview) } else { // focus on first result, then also dispatch preview immediately const firstChild = results.firstElementChild as HTMLElement firstChild.classList.add("focus") currentHover = firstChild as HTMLInputElement await displayPreview(firstChild) } } async function fetchContent(slug: FullSlug): Promise { if (fetchContentCache.has(slug)) { return fetchContentCache.get(slug) as Element[] } const targetUrl = resolveUrl(slug).toString() const contents = await fetch(targetUrl) .then((res) => res.text()) .then((contents) => { if (contents === undefined) { throw new Error(`Could not fetch ${targetUrl}`) } const html = p.parseFromString(contents ?? "", "text/html") normalizeRelativeURLs(html, targetUrl) return [...html.getElementsByClassName("popover-hint")] }) fetchContentCache.set(slug, contents) return contents } async function displayPreview(el: HTMLElement | null) { if (!searchLayout || !enablePreview || !el || !preview) return const slug = el.id as FullSlug const innerDiv = await fetchContent(slug).then((contents) => contents.flatMap((el) => [...highlightHTML(currentSearchTerm, el as HTMLElement).children]), ) previewInner = document.createElement("div") previewInner.classList.add("preview-inner") previewInner.append(...innerDiv) preview.replaceChildren(previewInner) // scroll to longest const highlights = [...preview.getElementsByClassName("highlight")].sort( (a, b) => b.innerHTML.length - a.innerHTML.length, ) highlights[0]?.scrollIntoView({ block: "start" }) } async function onType(e: HTMLElementEventMap["input"]) { if (!searchLayout || !index) return currentSearchTerm = (e.target as HTMLInputElement).value searchLayout.classList.toggle("display-results", currentSearchTerm !== "") searchType = currentSearchTerm.startsWith("#") ? "tags" : "basic" let searchResults: DefaultDocumentSearchResults if (searchType === "tags") { currentSearchTerm = currentSearchTerm.substring(1).trim() const separatorIndex = currentSearchTerm.indexOf(" ") if (separatorIndex != -1) { // search by title and content index and then filter by tag (implemented in flexsearch) const tag = currentSearchTerm.substring(0, separatorIndex) const query = currentSearchTerm.substring(separatorIndex + 1).trim() searchResults = await index.searchAsync({ query: query, // return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch) limit: Math.max(numSearchResults, 10000), index: ["title", "content"], tag: { tags: tag }, }) for (let searchResult of searchResults) { searchResult.result = searchResult.result.slice(0, numSearchResults) } // set search type to basic and remove tag from term for proper highlightning and scroll searchType = "basic" currentSearchTerm = query } else { // default search by tags index searchResults = await index.searchAsync({ query: currentSearchTerm, limit: numSearchResults, index: ["tags"], }) } } else if (searchType === "basic") { searchResults = await index.searchAsync({ query: currentSearchTerm, limit: numSearchResults, index: ["title", "content"], }) } const getByField = (field: string): number[] => { const results = searchResults.filter((x) => x.field === field) return results.length === 0 ? [] : ([...results[0].result] as number[]) } // order titles ahead of content const allIds: Set = new Set([ ...getByField("title"), ...getByField("content"), ...getByField("tags"), ]) const finalResults = [...allIds].map((id) => formatForDisplay(currentSearchTerm, id)) await displayResults(finalResults) } document.addEventListener("keydown", shortcutHandler) window.addCleanup(() => document.removeEventListener("keydown", shortcutHandler)) searchButton.addEventListener("click", () => showSearch("basic")) window.addCleanup(() => searchButton.removeEventListener("click", () => showSearch("basic"))) searchBar.addEventListener("input", onType) window.addCleanup(() => searchBar.removeEventListener("input", onType)) registerEscapeHandler(container, hideSearch) await fillDocument(data) } /** * Fills flexsearch document with data * @param index index to fill * @param data data to fill index with */ let indexPopulated = false async function fillDocument(data: ContentIndex) { if (indexPopulated) return let id = 0 const promises: Array> = [] for (const [slug, fileData] of Object.entries(data)) { promises.push( index.addAsync(id++, { id, slug: slug as FullSlug, title: fileData.title, content: fileData.content, tags: fileData.tags, }), ) } 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) } }) ================================================ FILE: quartz/components/scripts/search.test.ts ================================================ import test, { describe } from "node:test" import assert from "node:assert" // Inline the encoder function from search.inline.ts for testing const encoder = (str: string): string[] => { const tokens: string[] = [] let bufferStart = -1 let bufferEnd = -1 const lower = str.toLowerCase() let i = 0 for (const char of lower) { const code = char.codePointAt(0)! const isCJK = (code >= 0x3040 && code <= 0x309f) || (code >= 0x30a0 && code <= 0x30ff) || (code >= 0x4e00 && code <= 0x9fff) || (code >= 0xac00 && code <= 0xd7af) || (code >= 0x20000 && code <= 0x2a6df) const isWhitespace = code === 32 || code === 9 || code === 10 || code === 13 if (isCJK) { if (bufferStart !== -1) { tokens.push(lower.slice(bufferStart, bufferEnd)) bufferStart = -1 } tokens.push(char) } else if (isWhitespace) { if (bufferStart !== -1) { tokens.push(lower.slice(bufferStart, bufferEnd)) bufferStart = -1 } } else { if (bufferStart === -1) bufferStart = i bufferEnd = i + char.length } i += char.length } if (bufferStart !== -1) { tokens.push(lower.slice(bufferStart)) } return tokens } describe("search encoder", () => { describe("English text", () => { test("should tokenize simple English words", () => { const result = encoder("hello world") assert.deepStrictEqual(result, ["hello", "world"]) }) test("should handle multiple spaces", () => { const result = encoder("hello world") assert.deepStrictEqual(result, ["hello", "world"]) }) test("should handle tabs and newlines", () => { const result = encoder("hello\tworld\ntest") assert.deepStrictEqual(result, ["hello", "world", "test"]) }) test("should lowercase all text", () => { const result = encoder("Hello WORLD Test") assert.deepStrictEqual(result, ["hello", "world", "test"]) }) }) describe("CJK text", () => { test("should tokenize Japanese Hiragana character by character", () => { const result = encoder("こんにちは") assert.deepStrictEqual(result, ["こ", "ん", "に", "ち", "は"]) }) test("should tokenize Japanese Katakana character by character", () => { const result = encoder("コントロール") assert.deepStrictEqual(result, ["コ", "ン", "ト", "ロ", "ー", "ル"]) }) test("should tokenize Japanese Kanji character by character", () => { const result = encoder("日本語") assert.deepStrictEqual(result, ["日", "本", "語"]) }) test("should tokenize Korean Hangul character by character", () => { const result = encoder("안녕하세요") assert.deepStrictEqual(result, ["안", "녕", "하", "세", "요"]) }) test("should tokenize Chinese characters character by character", () => { const result = encoder("你好世界") assert.deepStrictEqual(result, ["你", "好", "世", "界"]) }) test("should handle mixed Hiragana/Katakana/Kanji", () => { const result = encoder("て以来") assert.deepStrictEqual(result, ["て", "以", "来"]) }) }) describe("Mixed CJK and English", () => { test("should handle Japanese with English words", () => { const result = encoder("hello 世界") assert.deepStrictEqual(result, ["hello", "世", "界"]) }) test("should handle English with Japanese words", () => { const result = encoder("世界 hello world") assert.deepStrictEqual(result, ["世", "界", "hello", "world"]) }) test("should handle complex mixed content", () => { const result = encoder("これはtest文章です") assert.deepStrictEqual(result, ["こ", "れ", "は", "test", "文", "章", "で", "す"]) }) test("should handle mixed Korean and English", () => { const result = encoder("hello 안녕 world") assert.deepStrictEqual(result, ["hello", "안", "녕", "world"]) }) test("should handle mixed Chinese and English", () => { const result = encoder("你好 world") assert.deepStrictEqual(result, ["你", "好", "world"]) }) }) describe("Edge cases", () => { test("should handle empty string", () => { const result = encoder("") assert.deepStrictEqual(result, []) }) test("should handle only whitespace", () => { const result = encoder(" \t\n ") assert.deepStrictEqual(result, []) }) test("should handle single character", () => { const result = encoder("a") assert.deepStrictEqual(result, ["a"]) }) test("should handle single CJK character", () => { const result = encoder("あ") assert.deepStrictEqual(result, ["あ"]) }) test("should handle CJK with trailing whitespace", () => { const result = encoder("日本語 ") assert.deepStrictEqual(result, ["日", "本", "語"]) }) test("should handle English with trailing whitespace", () => { const result = encoder("hello ") assert.deepStrictEqual(result, ["hello"]) }) }) }) ================================================ FILE: quartz/components/scripts/spa.inline.ts ================================================ import micromorph from "micromorph" import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path" import { fetchCanonical } from "./util" // adapted from `micromorph` // https://github.com/natemoo-re/micromorph const NODE_TYPE_ELEMENT = 1 let announcer = document.createElement("route-announcer") const isElement = (target: EventTarget | null): target is Element => (target as Node)?.nodeType === NODE_TYPE_ELEMENT const isLocalUrl = (href: string) => { try { const url = new URL(href) if (window.location.origin === url.origin) { return true } } catch (e) {} return false } const isSamePage = (url: URL): boolean => { const sameOrigin = url.origin === window.location.origin const samePath = url.pathname === window.location.pathname return sameOrigin && samePath } const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined => { if (!isElement(target)) return if (target.attributes.getNamedItem("target")?.value === "_blank") return const a = target.closest("a") if (!a) return if ("routerIgnore" in a.dataset) return const { href } = a if (!isLocalUrl(href)) return return { url: new URL(href), scroll: "routerNoscroll" in a.dataset ? false : undefined } } function notifyNav(url: FullSlug) { const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } }) document.dispatchEvent(event) } const cleanupFns: Set<(...args: any[]) => void> = new Set() 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 async function _navigate(url: URL, isBack: boolean = false) { isNavigating = true startLoading() p = p || new DOMParser() const contents = await fetchCanonical(url) .then((res) => { const contentType = res.headers.get("content-type") if (contentType?.startsWith("text/html")) { return res.text() } else { window.location.assign(url) } }) .catch(() => { window.location.assign(url) }) if (!contents) return // notify about to nav const event: CustomEventMap["prenav"] = new CustomEvent("prenav", { detail: {} }) document.dispatchEvent(event) // cleanup old cleanupFns.forEach((fn) => fn()) cleanupFns.clear() const html = p.parseFromString(contents, "text/html") normalizeRelativeURLs(html, url) let title = html.querySelector("title")?.textContent if (title) { document.title = title } else { const h1 = document.querySelector("h1") title = h1?.innerText ?? h1?.textContent ?? url.pathname } if (announcer.textContent !== title) { announcer.textContent = title } announcer.dataset.persist = "" html.body.appendChild(announcer) // morph body await micromorph(document.body, html.body) // scroll into place and add history if (!isBack) { if (url.hash) { const el = document.getElementById(decodeURIComponent(url.hash.substring(1))) el?.scrollIntoView() } else { window.scrollTo({ top: 0 }) } } // now, patch head, re-executing scripts const elementsToRemove = document.head.querySelectorAll(":not([data-persist])") elementsToRemove.forEach((el) => el.remove()) const elementsToAdd = html.head.querySelectorAll(":not([data-persist])") elementsToAdd.forEach((el) => document.head.appendChild(el)) // delay setting the url until now // at this point everything is loaded so changing the url should resolve to the correct addresses if (!isBack) { history.pushState({}, "", url) } notifyNav(getFullSlug(window)) 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 function createRouter() { if (typeof window !== "undefined") { window.addEventListener("click", async (event) => { const { url } = getOpts(event) ?? {} // dont hijack behaviour, just let browser act normally if (!url || event.ctrlKey || event.metaKey) return event.preventDefault() if (isSamePage(url) && url.hash) { const el = document.getElementById(decodeURIComponent(url.hash.substring(1))) el?.scrollIntoView() history.pushState({}, "", url) return } navigate(url, false) }) window.addEventListener("popstate", (event) => { const { url } = getOpts(event) ?? {} if (window.location.hash && window.location.pathname === url?.pathname) return navigate(new URL(window.location.toString()), true) return }) } return new (class Router { go(pathname: RelativeURL) { const url = new URL(pathname, window.location.toString()) return navigate(url, false) } back() { return window.history.back() } forward() { return window.history.forward() } })() } createRouter() notifyNav(getFullSlug(window)) if (!customElements.get("route-announcer")) { const attrs = { "aria-live": "assertive", "aria-atomic": "true", style: "position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px", } customElements.define( "route-announcer", class RouteAnnouncer extends HTMLElement { constructor() { super() } connectedCallback() { for (const [key, value] of Object.entries(attrs)) { this.setAttribute(key, value) } } }, ) } ================================================ FILE: quartz/components/scripts/toc.inline.ts ================================================ const observer = new IntersectionObserver((entries) => { for (const entry of entries) { const slug = entry.target.id const tocEntryElements = document.querySelectorAll(`a[data-for="${slug}"]`) const windowHeight = entry.rootBounds?.height if (windowHeight && tocEntryElements.length > 0) { if (entry.boundingClientRect.y < windowHeight) { tocEntryElements.forEach((tocEntryElement) => tocEntryElement.classList.add("in-view")) } else { tocEntryElements.forEach((tocEntryElement) => tocEntryElement.classList.remove("in-view")) } } } }) function toggleToc(this: HTMLElement) { this.classList.toggle("collapsed") this.setAttribute( "aria-expanded", this.getAttribute("aria-expanded") === "true" ? "false" : "true", ) const content = this.nextElementSibling as HTMLElement | undefined if (!content) return content.classList.toggle("collapsed") } function setupToc() { for (const toc of document.getElementsByClassName("toc")) { const button = toc.querySelector(".toc-header") const content = toc.querySelector(".toc-content") if (!button || !content) return button.addEventListener("click", toggleToc) window.addCleanup(() => button.removeEventListener("click", toggleToc)) } } document.addEventListener("nav", () => { setupToc() // update toc entry highlighting observer.disconnect() const headers = document.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]") headers.forEach((header) => observer.observe(header)) }) ================================================ FILE: quartz/components/scripts/util.ts ================================================ export function registerEscapeHandler(outsideContainer: HTMLElement | null, cb: () => void) { if (!outsideContainer) return function click(this: HTMLElement, e: HTMLElementEventMap["click"]) { if (e.target !== this) return e.preventDefault() e.stopPropagation() cb() } function esc(e: HTMLElementEventMap["keydown"]) { if (!e.key.startsWith("Esc")) return e.preventDefault() cb() } outsideContainer?.addEventListener("click", click) window.addCleanup(() => outsideContainer?.removeEventListener("click", click)) document.addEventListener("keydown", esc) window.addCleanup(() => document.removeEventListener("keydown", esc)) } export function removeAllChildren(node: HTMLElement) { while (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 = // export async function fetchCanonical(url: URL): Promise { 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 } ================================================ FILE: quartz/components/styles/backlinks.scss ================================================ @use "../../styles/variables.scss" as *; .backlinks { flex-direction: column; & > h3 { font-size: 1rem; margin: 0; } & > ul.overflow { list-style: none; padding: 0; margin: 0.5rem 0; max-height: calc(100% - 2rem); overscroll-behavior: contain; & > li { & > a { background-color: transparent; } } } } ================================================ FILE: quartz/components/styles/breadcrumbs.scss ================================================ .breadcrumb-container { margin: 0; margin-top: 0.75rem; padding: 0; display: flex; flex-direction: row; flex-wrap: wrap; gap: 0.5rem; } .breadcrumb-element { p { margin: 0; margin-left: 0.5rem; padding: 0; line-height: normal; } display: flex; flex-direction: row; align-items: center; justify-content: center; } ================================================ FILE: quartz/components/styles/clipboard.scss ================================================ .clipboard-button { position: absolute; display: flex; float: right; right: 0; padding: 0.4rem; margin: 0.3rem; color: var(--gray); border-color: var(--dark); background-color: var(--light); border: 1px solid; border-radius: 5px; opacity: 0; transition: 0.2s; & > svg { fill: var(--light); filter: contrast(0.3); } &:hover { cursor: pointer; border-color: var(--secondary); } &:focus { outline: 0; } } pre { &:hover > .clipboard-button { opacity: 1; transition: 0.2s; } } ================================================ FILE: quartz/components/styles/contentMeta.scss ================================================ .content-meta { margin-top: 0; color: var(--darkgray); &[show-comma="true"] { > *:not(:last-child) { margin-right: 8px; &::after { content: ","; } } } } ================================================ FILE: quartz/components/styles/darkmode.scss ================================================ .darkmode { cursor: pointer; padding: 0; position: relative; background: none; border: none; width: 20px; height: 32px; margin: 0; text-align: inherit; flex-shrink: 0; & svg { position: absolute; width: 20px; height: 20px; top: calc(50% - 10px); fill: var(--darkgray); transition: opacity 0.1s ease; } } :root[saved-theme="dark"] { color-scheme: dark; } :root[saved-theme="light"] { color-scheme: light; } :root[saved-theme="dark"] .darkmode { & > .dayIcon { display: none; } & > .nightIcon { display: inline; } } :root .darkmode { & > .dayIcon { display: inline; } & > .nightIcon { display: none; } } ================================================ FILE: quartz/components/styles/explorer.scss ================================================ @use "../../styles/variables.scss" as *; @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; border: none; text-align: left; cursor: pointer; padding: 0; color: var(--dark); display: flex; align-items: center; & h2 { font-size: 1rem; display: inline-block; margin: 0; } } .explorer-content { list-style: none; overflow: hidden; overflow-y: auto; margin-top: 0.5rem; & ul { list-style: none; margin: 0; padding: 0; &.explorer-ul { overscroll-behavior: contain; } & li > a { color: var(--dark); opacity: 0.75; pointer-events: all; &.active { opacity: 1; color: var(--tertiary); } } } .folder-outer { visibility: collapse; display: grid; grid-template-rows: 0fr; transition-property: grid-template-rows, visibility; transition-duration: 0.3s; transition-timing-function: ease-in-out; } .folder-outer.open { visibility: visible; grid-template-rows: 1fr; } .folder-outer > ul { overflow: hidden; margin-left: 6px; padding-left: 0.8rem; border-left: 1px solid var(--lightgray); } } .folder-container { flex-direction: row; display: flex; align-items: center; user-select: none; & div > a { color: var(--secondary); font-family: var(--headerFont); font-size: 0.95rem; font-weight: $semiBoldWeight; line-height: 1.5rem; display: inline-block; } & div > a:hover { color: var(--tertiary); } & div > button { color: var(--dark); background-color: transparent; border: none; text-align: left; cursor: pointer; padding-left: 0; padding-right: 0; display: flex; align-items: center; font-family: var(--headerFont); & span { font-size: 0.95rem; display: inline-block; color: var(--secondary); font-weight: $semiBoldWeight; margin: 0; line-height: 1.5rem; pointer-events: none; } } } .folder-icon { margin-right: 5px; color: var(--secondary); cursor: pointer; transition: transform 0.3s ease; backface-visibility: visible; flex-shrink: 0; } li:has(> .folder-outer:not(.open)) > .folder-container > svg { transform: rotate(-90deg); } .folder-icon:hover { color: var(--tertiary); } .explorer { @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: 100vw; 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); } } } } .mobile-no-scroll { @media all and ($mobile) { .explorer-content > .explorer-ul { overscroll-behavior: contain; } } } ================================================ FILE: quartz/components/styles/footer.scss ================================================ footer { text-align: left; margin-bottom: 4rem; opacity: 0.7; & ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: row; gap: 1rem; margin-top: -1rem; } } ================================================ FILE: quartz/components/styles/graph.scss ================================================ @use "../../styles/variables.scss" as *; .graph { & > h3 { font-size: 1rem; margin: 0; } & > .graph-outer { border-radius: 5px; border: 1px solid var(--lightgray); box-sizing: border-box; height: 250px; margin: 0.5em 0; position: relative; overflow: hidden; & > .global-graph-icon { cursor: pointer; background: none; border: none; color: var(--dark); opacity: 0.5; width: 24px; height: 24px; position: absolute; padding: 0.2rem; margin: 0.3rem; top: 0; right: 0; border-radius: 4px; background-color: transparent; transition: background-color 0.5s ease; cursor: pointer; &:hover { background-color: var(--lightgray); } } } & > .global-graph-outer { position: fixed; z-index: 9999; left: 0; top: 0; width: 100vw; height: 100%; backdrop-filter: blur(4px); display: none; overflow: hidden; &.active { display: inline-block; } & > .global-graph-container { border: 1px solid var(--lightgray); background-color: var(--light); border-radius: 5px; box-sizing: border-box; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 80vh; width: 80vw; @media all and not ($desktop) { width: 90%; } } } } ================================================ FILE: quartz/components/styles/legacyToc.scss ================================================ details.toc { & summary { cursor: pointer; &::marker { color: var(--dark); } & > * { padding-left: 0.25rem; display: inline-block; margin: 0; } } & ul { list-style: none; margin: 0.5rem 1.25rem; padding: 0; } @for $i from 1 through 6 { & .depth-#{$i} { padding-left: calc(1rem * #{$i}); } } } ================================================ FILE: quartz/components/styles/listPage.scss ================================================ @use "../../styles/variables.scss" as *; ul.section-ul { list-style: none; margin-top: 2em; padding-left: 0; } li.section-li { margin-bottom: 1em; & > .section { display: grid; grid-template-columns: fit-content(8em) 3fr 1fr; @media all and ($mobile) { & > .tags { display: none; } } & > .desc > h3 > a { background-color: transparent; } & .meta { margin: 0 1em 0 0; opacity: 0.6; } } } // modifications in popover context .popover .section { grid-template-columns: fit-content(8em) 1fr !important; & > .tags { display: none; } } ================================================ FILE: quartz/components/styles/mermaid.inline.scss ================================================ .expand-button { position: absolute; display: flex; float: right; padding: 0.4rem; margin: 0.3rem; right: 0; // NOTE: right will be set in mermaid.inline.ts color: var(--gray); border-color: var(--dark); background-color: var(--light); border: 1px solid; border-radius: 5px; opacity: 0; transition: 0.2s; & > svg { fill: var(--light); filter: contrast(0.3); } &:hover { cursor: pointer; border-color: var(--secondary); } &:focus { outline: 0; } } pre { &:hover > .expand-button { opacity: 1; transition: 0.2s; } } #mermaid-container { position: fixed; contain: layout; z-index: 999; left: 0; top: 0; width: 100vw; height: 100vh; overflow: hidden; display: none; backdrop-filter: blur(4px); background: rgba(0, 0, 0, 0.5); &.active { display: inline-block; } & > #mermaid-space { border: 1px solid var(--lightgray); background-color: var(--light); border-radius: 5px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 80vh; width: 80vw; overflow: hidden; & > .mermaid-content { position: relative; transform-origin: 0 0; transition: transform 0.1s ease; overflow: visible; min-height: 200px; min-width: 200px; pre { margin: 0; border: none; } svg { max-width: none; height: auto; } } & > .mermaid-controls { position: absolute; bottom: 20px; right: 20px; display: flex; gap: 8px; padding: 8px; background: var(--light); border: 1px solid var(--lightgray); border-radius: 6px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); z-index: 2; .mermaid-control-button { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 1px solid var(--lightgray); background: var(--light); color: var(--dark); border-radius: 4px; cursor: pointer; font-size: 16px; font-family: var(--bodyFont); transition: all 0.2s ease; &:hover { background: var(--lightgray); } &:active { transform: translateY(1px); } // Style the reset button differently &:nth-child(2) { width: auto; padding: 0 12px; font-size: 14px; } } } } } ================================================ FILE: quartz/components/styles/popover.scss ================================================ @use "../../styles/variables.scss" as *; @keyframes dropin { 0% { opacity: 0; visibility: hidden; } 1% { opacity: 0; } 100% { opacity: 1; visibility: visible; } } .popover { z-index: 999; position: fixed; overflow: visible; padding: 1rem; left: 0; top: 0; will-change: transform; & > .popover-inner { position: relative; width: 30rem; max-height: 20rem; padding: 0 1rem 1rem 1rem; font-weight: initial; font-style: initial; line-height: normal; font-size: initial; font-family: var(--bodyFont); border: 1px solid var(--lightgray); background-color: var(--light); border-radius: 5px; box-shadow: 6px 6px 36px 0 rgba(0, 0, 0, 0.25); overflow: auto; overscroll-behavior: contain; white-space: normal; user-select: none; cursor: default; } & > .popover-inner[data-content-type] { &[data-content-type*="pdf"], &[data-content-type*="image"] { padding: 0; max-height: 100%; } &[data-content-type*="image"] { img { margin: 0; border-radius: 0; display: block; } } &[data-content-type*="pdf"] { iframe { width: 100%; } } } h1 { font-size: 1.5rem; } visibility: hidden; opacity: 0; transition: opacity 0.3s ease, visibility 0.3s ease; @media all and ($mobile) { display: none !important; } } .active-popover, .popover:hover { animation: dropin 0.3s ease; animation-fill-mode: forwards; animation-delay: 0.2s; } ================================================ FILE: quartz/components/styles/readermode.scss ================================================ .readermode { cursor: pointer; padding: 0; position: relative; background: none; border: none; width: 20px; height: 32px; margin: 0; text-align: inherit; flex-shrink: 0; & svg { position: absolute; width: 20px; height: 20px; top: calc(50% - 10px); fill: var(--darkgray); stroke: var(--darkgray); transition: opacity 0.1s ease; } } :root[reader-mode="on"] { & .sidebar.left, & .sidebar.right { opacity: 0; transition: opacity 0.2s ease; &:hover { opacity: 1; } } } ================================================ FILE: quartz/components/styles/recentNotes.scss ================================================ .recent-notes { & > h3 { margin: 0.5rem 0 0 0; font-size: 1rem; } & > ul.recent-ul { list-style: none; margin-top: 1rem; padding-left: 0; & > li { margin: 1rem 0; .section > .desc > h3 > a { background-color: transparent; } .section > .meta { margin: 0 0 0.5rem 0; opacity: 0.6; } } } } ================================================ FILE: quartz/components/styles/search.scss ================================================ @use "../../styles/variables.scss" as *; .search { min-width: fit-content; max-width: 14rem; @media all and ($mobile) { flex-grow: 0.3; } & > .search-button { background-color: transparent; border: 1px var(--lightgray) solid; border-radius: 4px; font-family: inherit; font-size: inherit; height: 2rem; padding: 0 1rem 0 0; display: flex; align-items: center; text-align: inherit; cursor: pointer; white-space: nowrap; width: 100%; & > p { display: inline; color: var(--gray); text-wrap: unset; } & svg { cursor: pointer; width: 18px; min-width: 18px; margin: 0 0.5rem; .search-path { stroke: var(--darkgray); stroke-width: 1.5px; transition: stroke 0.5s ease; } } } & > .search-container { position: fixed; contain: layout; z-index: 999; left: 0; top: 0; width: 100vw; height: 100vh; overflow-y: auto; display: none; backdrop-filter: blur(4px); &.active { display: inline-block; } & > .search-space { width: 65%; margin-top: 12vh; margin-left: auto; margin-right: auto; @media all and not ($desktop) { width: 90%; } & > * { width: 100%; border-radius: 7px; background: var(--light); box-shadow: 0 14px 50px rgba(27, 33, 48, 0.12), 0 10px 30px rgba(27, 33, 48, 0.16); margin-bottom: 2em; } & > input { box-sizing: border-box; padding: 0.5em 1em; font-family: var(--bodyFont); color: var(--dark); font-size: 1.1em; border: 1px solid var(--lightgray); &:focus { outline: none; } } & > .search-layout { display: none; flex-direction: row; border: 1px solid var(--lightgray); flex: 0 0 100%; box-sizing: border-box; &.display-results { display: flex; } &[data-preview] > .results-container { flex: 0 0 min(30%, 450px); } @media all and not ($mobile) { &[data-preview] { & .result-card > p.preview { display: none; } & > div { &:first-child { border-right: 1px solid var(--lightgray); border-top-right-radius: unset; border-bottom-right-radius: unset; } &:last-child { border-top-left-radius: unset; border-bottom-left-radius: unset; } } } } & > div { height: calc(75vh - 12vh); border-radius: 5px; } @media all and ($mobile) { flex-direction: column; & > .preview-container { display: none !important; } &[data-preview] > .results-container { width: 100%; height: auto; flex: 0 0 100%; } } & .highlight { background: color-mix(in srgb, var(--tertiary) 60%, rgba(255, 255, 255, 0)); border-radius: 5px; scroll-margin-top: 2rem; } & > .preview-container { flex-grow: 1; display: block; overflow: hidden; font-family: inherit; color: var(--dark); line-height: 1.5em; font-weight: $normalWeight; overflow-y: auto; padding: 0 2rem; & .preview-inner { margin: 0 auto; width: min($pageWidth, 100%); } a[role="anchor"] { background-color: transparent; } } & > .results-container { overflow-y: auto; & .result-card { overflow: hidden; padding: 1em; cursor: pointer; transition: background 0.2s ease; border-bottom: 1px solid var(--lightgray); width: 100%; display: block; box-sizing: border-box; // normalize card props font-family: inherit; font-size: 100%; line-height: 1.15; margin: 0; text-transform: none; text-align: left; outline: none; font-weight: inherit; &:hover, &:focus, &.focus { background: var(--lightgray); } & > h3 { margin: 0; } @media all and not ($mobile) { & > p.card-description { display: none; } } & > ul.tags { margin-top: 0.45rem; margin-bottom: 0; } & > ul > li > p { border-radius: 8px; background-color: var(--highlight); padding: 0.2rem 0.4rem; margin: 0 0.1rem; line-height: 1.4rem; font-weight: $boldWeight; color: var(--secondary); &.match-tag { color: var(--tertiary); } } & > p { margin-bottom: 0; } } } } } } } ================================================ FILE: quartz/components/styles/toc.scss ================================================ @use "../../styles/variables.scss" as *; .toc { display: flex; flex-direction: column; overflow-y: hidden; min-height: 1.4rem; flex: 0 0.5 auto; &:has(button.toc-header.collapsed) { flex: 0 1 1.4rem; } } button.toc-header { background-color: transparent; border: none; text-align: left; cursor: pointer; padding: 0; color: var(--dark); display: flex; align-items: center; & h3 { font-size: 1rem; display: inline-block; margin: 0; } & .fold { margin-left: 0.5rem; transition: transform 0.3s ease; opacity: 0.8; } &.collapsed .fold { transform: rotateZ(-90deg); } } ul.toc-content.overflow { list-style: none; position: relative; margin: 0.5rem 0; padding: 0; max-height: calc(100% - 2rem); overscroll-behavior: contain; list-style: none; & > li > a { color: var(--dark); opacity: 0.35; transition: 0.5s ease opacity, 0.3s ease color; &.in-view { opacity: 0.75; } } @for $i from 0 through 6 { & .depth-#{$i} { padding-left: calc(1rem * #{$i}); } } } ================================================ FILE: quartz/components/types.ts ================================================ import { ComponentType, JSX } from "preact" import { StaticResources, StringResource } from "../util/resources" import { QuartzPluginData } from "../plugins/vfile" import { GlobalConfiguration } from "../cfg" import { Node } from "hast" import { BuildCtx } from "../util/ctx" export type QuartzComponentProps = { ctx: BuildCtx externalResources: StaticResources fileData: QuartzPluginData cfg: GlobalConfiguration children: (QuartzComponent | JSX.Element)[] tree: Node allFiles: QuartzPluginData[] displayClass?: "mobile-only" | "desktop-only" } & JSX.IntrinsicAttributes & { [key: string]: any } export type QuartzComponent = ComponentType & { css?: StringResource beforeDOMLoaded?: StringResource afterDOMLoaded?: StringResource } export type QuartzComponentConstructor = ( opts: Options, ) => QuartzComponent ================================================ FILE: quartz/i18n/index.ts ================================================ import { Translation, CalloutTranslation } from "./locales/definition" import enUs from "./locales/en-US" import enGb from "./locales/en-GB" import fr from "./locales/fr-FR" import it from "./locales/it-IT" import ja from "./locales/ja-JP" import de from "./locales/de-DE" import nl from "./locales/nl-NL" import ro from "./locales/ro-RO" import ca from "./locales/ca-ES" import es from "./locales/es-ES" import ar from "./locales/ar-SA" import uk from "./locales/uk-UA" import ru from "./locales/ru-RU" import ko from "./locales/ko-KR" import zh from "./locales/zh-CN" import zhTw from "./locales/zh-TW" import vi from "./locales/vi-VN" import pt from "./locales/pt-BR" import hu from "./locales/hu-HU" import fa from "./locales/fa-IR" import pl from "./locales/pl-PL" import cs from "./locales/cs-CZ" import tr from "./locales/tr-TR" import th from "./locales/th-TH" import lt from "./locales/lt-LT" import fi from "./locales/fi-FI" import no from "./locales/nb-NO" import id from "./locales/id-ID" import kk from "./locales/kk-KZ" import he from "./locales/he-IL" export const TRANSLATIONS = { "en-US": enUs, "en-GB": enGb, "fr-FR": fr, "it-IT": it, "ja-JP": ja, "de-DE": de, "nl-NL": nl, "nl-BE": nl, "ro-RO": ro, "ro-MD": ro, "ca-ES": ca, "es-ES": es, "ar-SA": ar, "ar-AE": ar, "ar-QA": ar, "ar-BH": ar, "ar-KW": ar, "ar-OM": ar, "ar-YE": ar, "ar-IR": ar, "ar-SY": ar, "ar-IQ": ar, "ar-JO": ar, "ar-PL": ar, "ar-LB": ar, "ar-EG": ar, "ar-SD": ar, "ar-LY": ar, "ar-MA": ar, "ar-TN": ar, "ar-DZ": ar, "ar-MR": ar, "uk-UA": uk, "ru-RU": ru, "ko-KR": ko, "zh-CN": zh, "zh-TW": zhTw, "vi-VN": vi, "pt-BR": pt, "hu-HU": hu, "fa-IR": fa, "pl-PL": pl, "cs-CZ": cs, "tr-TR": tr, "th-TH": th, "lt-LT": lt, "fi-FI": fi, "nb-NO": no, "id-ID": id, "kk-KZ": kk, "he-IL": he, } as const export const defaultTranslation = "en-US" export const i18n = (locale: ValidLocale): Translation => TRANSLATIONS[locale ?? defaultTranslation] export type ValidLocale = keyof typeof TRANSLATIONS export type ValidCallout = keyof CalloutTranslation ================================================ FILE: quartz/i18n/locales/ar-SA.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "غير معنون", description: "لم يتم تقديم أي وصف", }, direction: "rtl" as const, components: { callout: { note: "ملاحظة", abstract: "ملخص", info: "معلومات", todo: "للقيام", tip: "نصيحة", success: "نجاح", question: "سؤال", warning: "تحذير", failure: "فشل", danger: "خطر", bug: "خلل", example: "مثال", quote: "اقتباس", }, backlinks: { title: "وصلات العودة", noBacklinksFound: "لا يوجد وصلات عودة", }, themeToggle: { lightMode: "الوضع النهاري", darkMode: "الوضع الليلي", }, explorer: { title: "المستعرض", }, readerMode: { title: "وضع القارئ", }, footer: { createdWith: "أُنشئ باستخدام", }, graph: { title: "التمثيل التفاعلي", }, recentNotes: { title: "آخر الملاحظات", seeRemainingMore: ({ remaining }) => `تصفح ${remaining} أكثر →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `مقتبس من ${targetSlug}`, linkToOriginal: "وصلة للملاحظة الرئيسة", }, search: { title: "بحث", searchBarPlaceholder: "ابحث عن شيء ما", }, tableOfContents: { title: "فهرس المحتويات", }, contentMeta: { readingTime: ({ minutes }) => minutes == 1 ? `دقيقة أو أقل للقراءة` : minutes == 2 ? `دقيقتان للقراءة` : `${minutes} دقائق للقراءة`, }, }, pages: { rss: { recentNotes: "آخر الملاحظات", lastFewNotes: ({ count }) => `آخر ${count} ملاحظة`, }, error: { title: "غير موجود", notFound: "إما أن هذه الصفحة خاصة أو غير موجودة.", home: "العوده للصفحة الرئيسية", }, folderContent: { folder: "مجلد", itemsUnderFolder: ({ count }) => count === 1 ? "يوجد عنصر واحد فقط تحت هذا المجلد" : `يوجد ${count} عناصر تحت هذا المجلد.`, }, tagContent: { tag: "الوسم", tagIndex: "مؤشر الوسم", itemsUnderTag: ({ count }) => count === 1 ? "يوجد عنصر واحد فقط تحت هذا الوسم" : `يوجد ${count} عناصر تحت هذا الوسم.`, showingFirst: ({ count }) => `إظهار أول ${count} أوسمة.`, totalTags: ({ count }) => `يوجد ${count} أوسمة.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/ca-ES.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Sense títol", description: "Sense descripció", }, components: { callout: { note: "Nota", abstract: "Resum", info: "Informació", todo: "Per fer", tip: "Consell", success: "Èxit", question: "Pregunta", warning: "Advertència", failure: "Fall", danger: "Perill", bug: "Error", example: "Exemple", quote: "Cita", }, backlinks: { title: "Retroenllaç", noBacklinksFound: "No s'han trobat retroenllaços", }, themeToggle: { lightMode: "Mode clar", darkMode: "Mode fosc", }, readerMode: { title: "Mode lector", }, explorer: { title: "Explorador", }, footer: { createdWith: "Creat amb", }, graph: { title: "Vista Gràfica", }, recentNotes: { title: "Notes Recents", seeRemainingMore: ({ remaining }) => `Vegi ${remaining} més →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transcluit de ${targetSlug}`, linkToOriginal: "Enllaç a l'original", }, search: { title: "Cercar", searchBarPlaceholder: "Cerca alguna cosa", }, tableOfContents: { title: "Taula de Continguts", }, contentMeta: { readingTime: ({ minutes }) => `Es llegeix en ${minutes} min`, }, }, pages: { rss: { recentNotes: "Notes recents", lastFewNotes: ({ count }) => `Últimes ${count} notes`, }, error: { title: "No s'ha trobat.", notFound: "Aquesta pàgina és privada o no existeix.", home: "Torna a la pàgina principal", }, folderContent: { folder: "Carpeta", itemsUnderFolder: ({ count }) => count === 1 ? "1 article en aquesta carpeta." : `${count} articles en esta carpeta.`, }, tagContent: { tag: "Etiqueta", tagIndex: "índex d'Etiquetes", itemsUnderTag: ({ count }) => count === 1 ? "1 article amb aquesta etiqueta." : `${count} article amb aquesta etiqueta.`, showingFirst: ({ count }) => `Mostrant les primeres ${count} etiquetes.`, totalTags: ({ count }) => `S'han trobat ${count} etiquetes en total.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/cs-CZ.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Bez názvu", description: "Nebyl uveden žádný popis", }, components: { callout: { note: "Poznámka", abstract: "Abstract", info: "Info", todo: "Todo", tip: "Tip", success: "Úspěch", question: "Otázka", warning: "Upozornění", failure: "Chyba", danger: "Nebezpečí", bug: "Bug", example: "Příklad", quote: "Citace", }, backlinks: { title: "Příchozí odkazy", noBacklinksFound: "Nenalezeny žádné příchozí odkazy", }, themeToggle: { lightMode: "Světlý režim", darkMode: "Tmavý režim", }, readerMode: { title: "Režim čtečky", }, explorer: { title: "Procházet", }, footer: { createdWith: "Vytvořeno pomocí", }, graph: { title: "Graf", }, recentNotes: { title: "Nejnovější poznámky", seeRemainingMore: ({ remaining }) => `Zobraz ${remaining} dalších →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Zobrazení ${targetSlug}`, linkToOriginal: "Odkaz na původní dokument", }, search: { title: "Hledat", searchBarPlaceholder: "Hledejte něco", }, tableOfContents: { title: "Obsah", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min čtení`, }, }, pages: { rss: { recentNotes: "Nejnovější poznámky", lastFewNotes: ({ count }) => `Posledních ${count} poznámek`, }, error: { title: "Nenalezeno", notFound: "Tato stránka je buď soukromá, nebo neexistuje.", home: "Návrat na domovskou stránku", }, folderContent: { folder: "Složka", itemsUnderFolder: ({ count }) => count === 1 ? "1 položka v této složce." : `${count} položek v této složce.`, }, tagContent: { tag: "Tag", tagIndex: "Rejstřík tagů", itemsUnderTag: ({ count }) => count === 1 ? "1 položka s tímto tagem." : `${count} položek s tímto tagem.`, showingFirst: ({ count }) => `Zobrazují se první ${count} tagy.`, totalTags: ({ count }) => `Nalezeno celkem ${count} tagů.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/de-DE.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Unbenannt", description: "Keine Beschreibung angegeben", }, components: { callout: { note: "Hinweis", abstract: "Zusammenfassung", info: "Info", todo: "Zu erledigen", tip: "Tipp", success: "Erfolg", question: "Frage", warning: "Warnung", failure: "Fehlgeschlagen", danger: "Gefahr", bug: "Fehler", example: "Beispiel", quote: "Zitat", }, backlinks: { title: "Backlinks", noBacklinksFound: "Keine Backlinks gefunden", }, themeToggle: { lightMode: "Heller Modus", darkMode: "Dunkler Modus", }, readerMode: { title: "Lesemodus", }, explorer: { title: "Explorer", }, footer: { createdWith: "Erstellt mit", }, graph: { title: "Graphansicht", }, recentNotes: { title: "Zuletzt bearbeitete Seiten", seeRemainingMore: ({ remaining }) => `${remaining} weitere ansehen →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transklusion von ${targetSlug}`, linkToOriginal: "Link zum Original", }, search: { title: "Suche", searchBarPlaceholder: "Suche nach etwas", }, tableOfContents: { title: "Inhaltsverzeichnis", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} Min. Lesezeit`, }, }, pages: { rss: { recentNotes: "Zuletzt bearbeitete Seiten", lastFewNotes: ({ count }) => `Letzte ${count} Seiten`, }, error: { title: "Nicht gefunden", notFound: "Diese Seite ist entweder nicht öffentlich oder existiert nicht.", home: "Zur Startseite", }, folderContent: { folder: "Ordner", itemsUnderFolder: ({ count }) => count === 1 ? "1 Datei in diesem Ordner." : `${count} Dateien in diesem Ordner.`, }, tagContent: { tag: "Tag", tagIndex: "Tag-Übersicht", itemsUnderTag: ({ count }) => count === 1 ? "1 Datei mit diesem Tag." : `${count} Dateien mit diesem Tag.`, showingFirst: ({ count }) => `Die ersten ${count} Tags werden angezeigt.`, totalTags: ({ count }) => `${count} Tags insgesamt.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/definition.ts ================================================ import { FullSlug } from "../../util/path" export interface CalloutTranslation { note: string abstract: string info: string todo: string tip: string success: string question: string warning: string failure: string danger: string bug: string example: string quote: string } export interface Translation { propertyDefaults: { title: string description: string } direction?: "ltr" | "rtl" components: { callout: CalloutTranslation backlinks: { title: string noBacklinksFound: string } themeToggle: { lightMode: string darkMode: string } readerMode: { title: string } explorer: { title: string } footer: { createdWith: string } graph: { title: string } recentNotes: { title: string seeRemainingMore: (variables: { remaining: number }) => string } transcludes: { transcludeOf: (variables: { targetSlug: FullSlug }) => string linkToOriginal: string } search: { title: string searchBarPlaceholder: string } tableOfContents: { title: string } contentMeta: { readingTime: (variables: { minutes: number }) => string } } pages: { rss: { recentNotes: string lastFewNotes: (variables: { count: number }) => string } error: { title: string notFound: string home: string } folderContent: { folder: string itemsUnderFolder: (variables: { count: number }) => string } tagContent: { tag: string tagIndex: string itemsUnderTag: (variables: { count: number }) => string showingFirst: (variables: { count: number }) => string totalTags: (variables: { count: number }) => string } } } ================================================ FILE: quartz/i18n/locales/en-GB.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Untitled", description: "No description provided", }, components: { callout: { note: "Note", abstract: "Abstract", info: "Info", todo: "To-Do", tip: "Tip", success: "Success", question: "Question", warning: "Warning", failure: "Failure", danger: "Danger", bug: "Bug", example: "Example", quote: "Quote", }, backlinks: { title: "Backlinks", noBacklinksFound: "No backlinks found", }, themeToggle: { lightMode: "Light mode", darkMode: "Dark mode", }, readerMode: { title: "Reader mode", }, explorer: { title: "Explorer", }, footer: { createdWith: "Created with", }, graph: { title: "Graph View", }, recentNotes: { title: "Recent Notes", seeRemainingMore: ({ remaining }) => `See ${remaining} more →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transclude of ${targetSlug}`, linkToOriginal: "Link to original", }, search: { title: "Search", searchBarPlaceholder: "Search for something", }, tableOfContents: { title: "Table of Contents", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min read`, }, }, pages: { rss: { recentNotes: "Recent notes", lastFewNotes: ({ count }) => `Last ${count} notes`, }, error: { title: "Not Found", notFound: "Either this page is private or doesn't exist.", home: "Return to Homepage", }, folderContent: { folder: "Folder", itemsUnderFolder: ({ count }) => count === 1 ? "1 item under this folder." : `${count} items under this folder.`, }, tagContent: { tag: "Tag", tagIndex: "Tag Index", itemsUnderTag: ({ count }) => count === 1 ? "1 item with this tag." : `${count} items with this tag.`, showingFirst: ({ count }) => `Showing first ${count} tags.`, totalTags: ({ count }) => `Found ${count} total tags.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/en-US.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Untitled", description: "No description provided", }, components: { callout: { note: "Note", abstract: "Abstract", info: "Info", todo: "Todo", tip: "Tip", success: "Success", question: "Question", warning: "Warning", failure: "Failure", danger: "Danger", bug: "Bug", example: "Example", quote: "Quote", }, backlinks: { title: "Backlinks", noBacklinksFound: "No backlinks found", }, themeToggle: { lightMode: "Light mode", darkMode: "Dark mode", }, readerMode: { title: "Reader mode", }, explorer: { title: "Explorer", }, footer: { createdWith: "Created with", }, graph: { title: "Graph View", }, recentNotes: { title: "Recent Notes", seeRemainingMore: ({ remaining }) => `See ${remaining} more →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transclude of ${targetSlug}`, linkToOriginal: "Link to original", }, search: { title: "Search", searchBarPlaceholder: "Search for something", }, tableOfContents: { title: "Table of Contents", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min read`, }, }, pages: { rss: { recentNotes: "Recent notes", lastFewNotes: ({ count }) => `Last ${count} notes`, }, error: { title: "Not Found", notFound: "Either this page is private or doesn't exist.", home: "Return to Homepage", }, folderContent: { folder: "Folder", itemsUnderFolder: ({ count }) => count === 1 ? "1 item under this folder." : `${count} items under this folder.`, }, tagContent: { tag: "Tag", tagIndex: "Tag Index", itemsUnderTag: ({ count }) => count === 1 ? "1 item with this tag." : `${count} items with this tag.`, showingFirst: ({ count }) => `Showing first ${count} tags.`, totalTags: ({ count }) => `Found ${count} total tags.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/es-ES.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Sin título", description: "Sin descripción", }, components: { callout: { note: "Nota", abstract: "Resumen", info: "Información", todo: "Por hacer", tip: "Consejo", success: "Éxito", question: "Pregunta", warning: "Advertencia", failure: "Fallo", danger: "Peligro", bug: "Error", example: "Ejemplo", quote: "Cita", }, backlinks: { title: "Retroenlaces", noBacklinksFound: "No se han encontrado retroenlaces", }, themeToggle: { lightMode: "Modo claro", darkMode: "Modo oscuro", }, readerMode: { title: "Modo lector", }, explorer: { title: "Explorador", }, footer: { createdWith: "Creado con", }, graph: { title: "Vista Gráfica", }, recentNotes: { title: "Notas Recientes", seeRemainingMore: ({ remaining }) => `Vea ${remaining} más →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transcluido de ${targetSlug}`, linkToOriginal: "Enlace al original", }, search: { title: "Buscar", searchBarPlaceholder: "Busca algo", }, tableOfContents: { title: "Tabla de Contenidos", }, contentMeta: { readingTime: ({ minutes }) => `Se lee en ${minutes} min`, }, }, pages: { rss: { recentNotes: "Notas recientes", lastFewNotes: ({ count }) => `Últimas ${count} notas`, }, error: { title: "No se ha encontrado.", notFound: "Esta página es privada o no existe.", home: "Regresa a la página principal", }, folderContent: { folder: "Carpeta", itemsUnderFolder: ({ count }) => count === 1 ? "1 artículo en esta carpeta." : `${count} artículos en esta carpeta.`, }, tagContent: { tag: "Etiqueta", tagIndex: "Índice de Etiquetas", itemsUnderTag: ({ count }) => count === 1 ? "1 artículo con esta etiqueta." : `${count} artículos con esta etiqueta.`, showingFirst: ({ count }) => `Mostrando las primeras ${count} etiquetas.`, totalTags: ({ count }) => `Se han encontrado ${count} etiquetas en total.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/fa-IR.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "بدون عنوان", description: "توضیح خاصی اضافه نشده است", }, direction: "rtl" as const, components: { callout: { note: "یادداشت", abstract: "چکیده", info: "اطلاعات", todo: "اقدام", tip: "نکته", success: "تیک", question: "سؤال", warning: "هشدار", failure: "شکست", danger: "خطر", bug: "باگ", example: "مثال", quote: "نقل قول", }, backlinks: { title: "بک‌لینک‌ها", noBacklinksFound: "بدون بک‌لینک", }, themeToggle: { lightMode: "حالت روشن", darkMode: "حالت تاریک", }, readerMode: { title: "حالت خواندن", }, explorer: { title: "مطالب", }, footer: { createdWith: "ساخته شده با", }, graph: { title: "نمای گراف", }, recentNotes: { title: "یادداشت‌های اخیر", seeRemainingMore: ({ remaining }) => `${remaining} یادداشت دیگر →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `از ${targetSlug}`, linkToOriginal: "پیوند به اصلی", }, search: { title: "جستجو", searchBarPlaceholder: "مطلبی را جستجو کنید", }, tableOfContents: { title: "فهرست", }, contentMeta: { readingTime: ({ minutes }) => `زمان تقریبی مطالعه: ${minutes} دقیقه`, }, }, pages: { rss: { recentNotes: "یادداشت‌های اخیر", lastFewNotes: ({ count }) => `${count} یادداشت اخیر`, }, error: { title: "یافت نشد", notFound: "این صفحه یا خصوصی است یا وجود ندارد", home: "بازگشت به صفحه اصلی", }, folderContent: { folder: "پوشه", itemsUnderFolder: ({ count }) => count === 1 ? ".یک مطلب در این پوشه است" : `${count} مطلب در این پوشه است.`, }, tagContent: { tag: "برچسب", tagIndex: "فهرست برچسب‌ها", itemsUnderTag: ({ count }) => count === 1 ? "یک مطلب با این برچسب" : `${count} مطلب با این برچسب.`, showingFirst: ({ count }) => `در حال نمایش ${count} برچسب.`, totalTags: ({ count }) => `${count} برچسب یافت شد.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/fi-FI.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Nimetön", description: "Ei kuvausta saatavilla", }, components: { callout: { note: "Merkintä", abstract: "Tiivistelmä", info: "Info", todo: "Tehtävälista", tip: "Vinkki", success: "Onnistuminen", question: "Kysymys", warning: "Varoitus", failure: "Epäonnistuminen", danger: "Vaara", bug: "Virhe", example: "Esimerkki", quote: "Lainaus", }, backlinks: { title: "Takalinkit", noBacklinksFound: "Takalinkkejä ei löytynyt", }, themeToggle: { lightMode: "Vaalea tila", darkMode: "Tumma tila", }, readerMode: { title: "Lukijatila", }, explorer: { title: "Selain", }, footer: { createdWith: "Luotu käyttäen", }, graph: { title: "Verkkonäkymä", }, recentNotes: { title: "Viimeisimmät muistiinpanot", seeRemainingMore: ({ remaining }) => `Näytä ${remaining} lisää →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Upote kohteesta ${targetSlug}`, linkToOriginal: "Linkki alkuperäiseen", }, search: { title: "Haku", searchBarPlaceholder: "Hae jotain", }, tableOfContents: { title: "Sisällysluettelo", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min lukuaika`, }, }, pages: { rss: { recentNotes: "Viimeisimmät muistiinpanot", lastFewNotes: ({ count }) => `Viimeiset ${count} muistiinpanoa`, }, error: { title: "Ei löytynyt", notFound: "Tämä sivu on joko yksityinen tai sitä ei ole olemassa.", home: "Palaa etusivulle", }, folderContent: { folder: "Kansio", itemsUnderFolder: ({ count }) => count === 1 ? "1 kohde tässä kansiossa." : `${count} kohdetta tässä kansiossa.`, }, tagContent: { tag: "Tunniste", tagIndex: "Tunnisteluettelo", itemsUnderTag: ({ count }) => count === 1 ? "1 kohde tällä tunnisteella." : `${count} kohdetta tällä tunnisteella.`, showingFirst: ({ count }) => `Näytetään ensimmäiset ${count} tunnistetta.`, totalTags: ({ count }) => `Löytyi yhteensä ${count} tunnistetta.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/fr-FR.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Sans titre", description: "Aucune description fournie", }, components: { callout: { note: "Note", abstract: "Résumé", info: "Info", todo: "À faire", tip: "Conseil", success: "Succès", question: "Question", warning: "Avertissement", failure: "Échec", danger: "Danger", bug: "Bogue", example: "Exemple", quote: "Citation", }, backlinks: { title: "Liens retour", noBacklinksFound: "Aucun lien retour trouvé", }, themeToggle: { lightMode: "Mode clair", darkMode: "Mode sombre", }, readerMode: { title: "Mode lecture", }, explorer: { title: "Explorateur", }, footer: { createdWith: "Créé avec", }, graph: { title: "Vue Graphique", }, recentNotes: { title: "Notes Récentes", seeRemainingMore: ({ remaining }) => `Voir ${remaining} de plus →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transclusion de ${targetSlug}`, linkToOriginal: "Lien vers l'original", }, search: { title: "Recherche", searchBarPlaceholder: "Rechercher quelque chose", }, tableOfContents: { title: "Table des Matières", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min de lecture`, }, }, pages: { rss: { recentNotes: "Notes récentes", lastFewNotes: ({ count }) => `Les dernières ${count} notes`, }, error: { title: "Introuvable", notFound: "Cette page est soit privée, soit elle n'existe pas.", home: "Retour à la page d'accueil", }, folderContent: { folder: "Dossier", itemsUnderFolder: ({ count }) => count === 1 ? "1 élément sous ce dossier." : `${count} éléments sous ce dossier.`, }, tagContent: { tag: "Étiquette", tagIndex: "Index des étiquettes", itemsUnderTag: ({ count }) => count === 1 ? "1 élément avec cette étiquette." : `${count} éléments avec cette étiquette.`, showingFirst: ({ count }) => `Affichage des premières ${count} étiquettes.`, totalTags: ({ count }) => `Trouvé ${count} étiquettes au total.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/he-IL.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "ללא כותרת", description: "לא סופק תיאור", }, direction: "rtl" as const, components: { callout: { note: "הערה", abstract: "תקציר", info: "מידע", todo: "לעשות", tip: "טיפ", success: "הצלחה", question: "שאלה", warning: "אזהרה", failure: "כשלון", danger: "סכנה", bug: "באג", example: "דוגמה", quote: "ציטוט", }, backlinks: { title: "קישורים חוזרים", noBacklinksFound: "לא נמצאו קישורים חוזרים", }, themeToggle: { lightMode: "מצב בהיר", darkMode: "מצב כהה", }, readerMode: { title: "מצב קריאה", }, explorer: { title: "סייר", }, footer: { createdWith: "נוצר באמצעות", }, graph: { title: "מבט גרף", }, recentNotes: { title: "הערות אחרונות", seeRemainingMore: ({ remaining }) => `עיין ב ${remaining} נוספים →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `מצוטט מ ${targetSlug}`, linkToOriginal: "קישור למקורי", }, search: { title: "חיפוש", searchBarPlaceholder: "חפשו משהו", }, tableOfContents: { title: "תוכן עניינים", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} דקות קריאה`, }, }, pages: { rss: { recentNotes: "הערות אחרונות", lastFewNotes: ({ count }) => `${count} הערות אחרונות`, }, error: { title: "לא נמצא", notFound: "העמוד הזה פרטי או לא קיים.", home: "חזרה לעמוד הבית", }, folderContent: { folder: "תיקייה", itemsUnderFolder: ({ count }) => count === 1 ? "פריט אחד תחת תיקייה זו." : `${count} פריטים תחת תיקייה זו.`, }, tagContent: { tag: "תגית", tagIndex: "מפתח התגיות", itemsUnderTag: ({ count }) => count === 1 ? "פריט אחד עם תגית זו." : `${count} פריטים עם תגית זו.`, showingFirst: ({ count }) => `מראה את ה-${count} תגיות הראשונות.`, totalTags: ({ count }) => `${count} תגיות נמצאו סך הכל.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/hu-HU.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Névtelen", description: "Nincs leírás", }, components: { callout: { note: "Jegyzet", abstract: "Abstract", info: "Információ", todo: "Tennivaló", tip: "Tipp", success: "Siker", question: "Kérdés", warning: "Figyelmeztetés", failure: "Hiba", danger: "Veszély", bug: "Bug", example: "Példa", quote: "Idézet", }, backlinks: { title: "Visszautalások", noBacklinksFound: "Nincs visszautalás", }, themeToggle: { lightMode: "Világos mód", darkMode: "Sötét mód", }, readerMode: { title: "Olvasó mód", }, explorer: { title: "Fájlböngésző", }, footer: { createdWith: "Készítve ezzel:", }, graph: { title: "Grafikonnézet", }, recentNotes: { title: "Legutóbbi jegyzetek", seeRemainingMore: ({ remaining }) => `${remaining} további megtekintése →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `${targetSlug} áthivatkozása`, linkToOriginal: "Hivatkozás az eredetire", }, search: { title: "Keresés", searchBarPlaceholder: "Keress valamire", }, tableOfContents: { title: "Tartalomjegyzék", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} perces olvasás`, }, }, pages: { rss: { recentNotes: "Legutóbbi jegyzetek", lastFewNotes: ({ count }) => `Legutóbbi ${count} jegyzet`, }, error: { title: "Nem található", notFound: "Ez a lap vagy privát vagy nem létezik.", home: "Vissza a kezdőlapra", }, folderContent: { folder: "Mappa", itemsUnderFolder: ({ count }) => `Ebben a mappában ${count} elem található.`, }, tagContent: { tag: "Címke", tagIndex: "Címke index", itemsUnderTag: ({ count }) => `${count} elem található ezzel a címkével.`, showingFirst: ({ count }) => `Első ${count} címke megjelenítve.`, totalTags: ({ count }) => `Összesen ${count} címke található.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/id-ID.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Tanpa Judul", description: "Tidak ada deskripsi", }, components: { callout: { note: "Catatan", abstract: "Abstrak", info: "Info", todo: "Daftar Tugas", tip: "Tips", success: "Berhasil", question: "Pertanyaan", warning: "Peringatan", failure: "Gagal", danger: "Bahaya", bug: "Bug", example: "Contoh", quote: "Kutipan", }, backlinks: { title: "Tautan Balik", noBacklinksFound: "Tidak ada tautan balik ditemukan", }, themeToggle: { lightMode: "Mode Terang", darkMode: "Mode Gelap", }, readerMode: { title: "Mode Pembaca", }, explorer: { title: "Penjelajah", }, footer: { createdWith: "Dibuat dengan", }, graph: { title: "Tampilan Grafik", }, recentNotes: { title: "Catatan Terbaru", seeRemainingMore: ({ remaining }) => `Lihat ${remaining} lagi →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transklusi dari ${targetSlug}`, linkToOriginal: "Tautan ke asli", }, search: { title: "Cari", searchBarPlaceholder: "Cari sesuatu", }, tableOfContents: { title: "Daftar Isi", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} menit baca`, }, }, pages: { rss: { recentNotes: "Catatan terbaru", lastFewNotes: ({ count }) => `${count} catatan terakhir`, }, error: { title: "Tidak Ditemukan", notFound: "Halaman ini bersifat privat atau tidak ada.", home: "Kembali ke Beranda", }, folderContent: { folder: "Folder", itemsUnderFolder: ({ count }) => count === 1 ? "1 item di bawah folder ini." : `${count} item di bawah folder ini.`, }, tagContent: { tag: "Tag", tagIndex: "Indeks Tag", itemsUnderTag: ({ count }) => count === 1 ? "1 item dengan tag ini." : `${count} item dengan tag ini.`, showingFirst: ({ count }) => `Menampilkan ${count} tag pertama.`, totalTags: ({ count }) => `Ditemukan total ${count} tag.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/it-IT.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Senza titolo", description: "Nessuna descrizione", }, components: { callout: { note: "Nota", abstract: "Abstract", info: "Info", todo: "Da fare", tip: "Consiglio", success: "Completato", question: "Domanda", warning: "Attenzione", failure: "Errore", danger: "Pericolo", bug: "Problema", example: "Esempio", quote: "Citazione", }, backlinks: { title: "Link entranti", noBacklinksFound: "Nessun link entrante", }, themeToggle: { lightMode: "Tema chiaro", darkMode: "Tema scuro", }, readerMode: { title: "Modalità lettura", }, explorer: { title: "Esplora", }, footer: { createdWith: "Creato con", }, graph: { title: "Vista grafico", }, recentNotes: { title: "Note recenti", seeRemainingMore: ({ remaining }) => remaining === 1 ? "Vedi 1 altra →" : `Vedi altre ${remaining} →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Inclusione di ${targetSlug}`, linkToOriginal: "Link all'originale", }, search: { title: "Cerca", searchBarPlaceholder: "Cerca qualcosa", }, tableOfContents: { title: "Indice", }, contentMeta: { readingTime: ({ minutes }) => (minutes === 1 ? "1 minuto" : `${minutes} minuti`), }, }, pages: { rss: { recentNotes: "Note recenti", lastFewNotes: ({ count }) => (count === 1 ? "Ultima nota" : `Ultime ${count} note`), }, error: { title: "Non trovato", notFound: "Questa pagina è privata o non esiste.", home: "Ritorna alla home page", }, folderContent: { folder: "Cartella", itemsUnderFolder: ({ count }) => count === 1 ? "1 oggetto in questa cartella." : `${count} oggetti in questa cartella.`, }, tagContent: { tag: "Etichetta", tagIndex: "Indice etichette", itemsUnderTag: ({ count }) => count === 1 ? "1 oggetto con questa etichetta." : `${count} oggetti con questa etichetta.`, showingFirst: ({ count }) => (count === 1 ? "Prima etichetta." : `Prime ${count} etichette.`), totalTags: ({ count }) => count === 1 ? "Trovata 1 etichetta in totale." : `Trovate ${count} etichette totali.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/ja-JP.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "無題", description: "説明なし", }, components: { callout: { note: "ノート", abstract: "抄録", info: "情報", todo: "やるべきこと", tip: "ヒント", success: "成功", question: "質問", warning: "警告", failure: "失敗", danger: "危険", bug: "バグ", example: "例", quote: "引用", }, backlinks: { title: "バックリンク", noBacklinksFound: "バックリンクはありません", }, themeToggle: { lightMode: "ライトモード", darkMode: "ダークモード", }, readerMode: { title: "リーダーモード", }, explorer: { title: "エクスプローラー", }, footer: { createdWith: "作成", }, graph: { title: "グラフビュー", }, recentNotes: { title: "最近の記事", seeRemainingMore: ({ remaining }) => `さらに${remaining}件 →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `${targetSlug}のまとめ`, linkToOriginal: "元記事へのリンク", }, search: { title: "検索", searchBarPlaceholder: "検索ワードを入力", }, tableOfContents: { title: "目次", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min read`, }, }, pages: { rss: { recentNotes: "最近の記事", lastFewNotes: ({ count }) => `最新の${count}件`, }, error: { title: "Not Found", notFound: "ページが存在しないか、非公開設定になっています。", home: "ホームページに戻る", }, folderContent: { folder: "フォルダ", itemsUnderFolder: ({ count }) => `${count}件のページ`, }, tagContent: { tag: "タグ", tagIndex: "タグ一覧", itemsUnderTag: ({ count }) => `${count}件のページ`, showingFirst: ({ count }) => `のうち最初の${count}件を表示しています`, totalTags: ({ count }) => `全${count}個のタグを表示中`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/kk-KZ.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Атаусыз", description: "Сипаттама берілмеген", }, components: { callout: { note: "Ескерту", abstract: "Аннотация", info: "Ақпарат", todo: "Істеу керек", tip: "Кеңес", success: "Сәттілік", question: "Сұрақ", warning: "Ескерту", failure: "Қате", danger: "Қауіп", bug: "Қате", example: "Мысал", quote: "Дәйексөз", }, backlinks: { title: "Артқа сілтемелер", noBacklinksFound: "Артқа сілтемелер табылмады", }, themeToggle: { lightMode: "Жарық режимі", darkMode: "Қараңғы режим", }, readerMode: { title: "Оқу режимі", }, explorer: { title: "Зерттеуші", }, footer: { createdWith: "Құрастырылған құрал:", }, graph: { title: "Граф көрінісі", }, recentNotes: { title: "Соңғы жазбалар", seeRemainingMore: ({ remaining }) => `Тағы ${remaining} жазбаны қарау →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `${targetSlug} кірістіру`, linkToOriginal: "Бастапқыға сілтеме", }, search: { title: "Іздеу", searchBarPlaceholder: "Бірдеңе іздеу", }, tableOfContents: { title: "Мазмұны", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} мин оқу`, }, }, pages: { rss: { recentNotes: "Соңғы жазбалар", lastFewNotes: ({ count }) => `Соңғы ${count} жазба`, }, error: { title: "Табылмады", notFound: "Бұл бет жеке немесе жоқ болуы мүмкін.", home: "Басты бетке оралу", }, folderContent: { folder: "Қалта", itemsUnderFolder: ({ count }) => count === 1 ? "Бұл қалтада 1 элемент бар." : `Бұл қалтада ${count} элемент бар.`, }, tagContent: { tag: "Тег", tagIndex: "Тегтер индексі", itemsUnderTag: ({ count }) => count === 1 ? "Бұл тегпен 1 элемент." : `Бұл тегпен ${count} элемент.`, showingFirst: ({ count }) => `Алғашқы ${count} тег көрсетілуде.`, totalTags: ({ count }) => `Барлығы ${count} тег табылды.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/ko-KR.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "제목 없음", description: "설명 없음", }, components: { callout: { note: "노트", abstract: "개요", info: "정보", todo: "할일", tip: "팁", success: "성공", question: "질문", warning: "주의", failure: "실패", danger: "위험", bug: "버그", example: "예시", quote: "인용", }, backlinks: { title: "백링크", noBacklinksFound: "백링크가 없습니다.", }, themeToggle: { lightMode: "라이트 모드", darkMode: "다크 모드", }, readerMode: { title: "리더 모드", }, explorer: { title: "탐색기", }, footer: { createdWith: "Created with", }, graph: { title: "그래프 뷰", }, recentNotes: { title: "최근 게시글", seeRemainingMore: ({ remaining }) => `${remaining}건 더보기 →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `${targetSlug}의 포함`, linkToOriginal: "원본 링크", }, search: { title: "검색", searchBarPlaceholder: "검색어를 입력하세요", }, tableOfContents: { title: "목차", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min read`, }, }, pages: { rss: { recentNotes: "최근 게시글", lastFewNotes: ({ count }) => `최근 ${count} 건`, }, error: { title: "Not Found", notFound: "페이지가 존재하지 않거나 비공개 설정이 되어 있습니다.", home: "홈페이지로 돌아가기", }, folderContent: { folder: "폴더", itemsUnderFolder: ({ count }) => `${count}건의 항목`, }, tagContent: { tag: "태그", tagIndex: "태그 목록", itemsUnderTag: ({ count }) => `${count}건의 항목`, showingFirst: ({ count }) => `처음 ${count}개의 태그`, totalTags: ({ count }) => `총 ${count}개의 태그를 찾았습니다.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/lt-LT.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Be Pavadinimo", description: "Aprašymas Nepateiktas", }, components: { callout: { note: "Pastaba", abstract: "Santrauka", info: "Informacija", todo: "Darbų sąrašas", tip: "Patarimas", success: "Sėkmingas", question: "Klausimas", warning: "Įspėjimas", failure: "Nesėkmingas", danger: "Pavojus", bug: "Klaida", example: "Pavyzdys", quote: "Citata", }, backlinks: { title: "Atgalinės Nuorodos", noBacklinksFound: "Atgalinių Nuorodų Nerasta", }, themeToggle: { lightMode: "Šviesus Režimas", darkMode: "Tamsus Režimas", }, readerMode: { title: "Modalità lettore", }, explorer: { title: "Naršyklė", }, footer: { createdWith: "Sukurta Su", }, graph: { title: "Grafiko Vaizdas", }, recentNotes: { title: "Naujausi Užrašai", seeRemainingMore: ({ remaining }) => `Peržiūrėti dar ${remaining} →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Įterpimas iš ${targetSlug}`, linkToOriginal: "Nuoroda į originalą", }, search: { title: "Paieška", searchBarPlaceholder: "Ieškoti", }, tableOfContents: { title: "Turinys", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min skaitymo`, }, }, pages: { rss: { recentNotes: "Naujausi užrašai", lastFewNotes: ({ count }) => count === 1 ? "Paskutinis 1 užrašas" : count < 10 ? `Paskutiniai ${count} užrašai` : `Paskutiniai ${count} užrašų`, }, error: { title: "Nerasta", notFound: "Arba šis puslapis yra pasiekiamas tik tam tikriems vartotojams, arba tokio puslapio nėra.", home: "Grįžti į pagrindinį puslapį", }, folderContent: { folder: "Aplankas", itemsUnderFolder: ({ count }) => count === 1 ? "1 elementas šiame aplanke." : count < 10 ? `${count} elementai šiame aplanke.` : `${count} elementų šiame aplanke.`, }, tagContent: { tag: "Žyma", tagIndex: "Žymų indeksas", itemsUnderTag: ({ count }) => count === 1 ? "1 elementas su šia žyma." : count < 10 ? `${count} elementai su šia žyma.` : `${count} elementų su šia žyma.`, showingFirst: ({ count }) => count < 10 ? `Rodomos pirmosios ${count} žymos.` : `Rodomos pirmosios ${count} žymų.`, totalTags: ({ count }) => count === 1 ? "Rasta iš viso 1 žyma." : count < 10 ? `Rasta iš viso ${count} žymos.` : `Rasta iš viso ${count} žymų.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/nb-NO.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Uten navn", description: "Ingen beskrivelse angitt", }, components: { callout: { note: "Notis", abstract: "Abstrakt", info: "Info", todo: "Husk på", tip: "Tips", success: "Suksess", question: "Spørsmål", warning: "Advarsel", failure: "Feil", danger: "Farlig", bug: "Bug", example: "Eksempel", quote: "Sitat", }, backlinks: { title: "Tilbakekoblinger", noBacklinksFound: "Ingen tilbakekoblinger funnet", }, themeToggle: { lightMode: "Lys modus", darkMode: "Mørk modus", }, readerMode: { title: "Læsemodus", }, explorer: { title: "Utforsker", }, footer: { createdWith: "Laget med", }, graph: { title: "Graf-visning", }, recentNotes: { title: "Nylige notater", seeRemainingMore: ({ remaining }) => `Se ${remaining} til →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transkludering of ${targetSlug}`, linkToOriginal: "Lenke til original", }, search: { title: "Søk", searchBarPlaceholder: "Søk etter noe", }, tableOfContents: { title: "Oversikt", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min lesning`, }, }, pages: { rss: { recentNotes: "Nylige notat", lastFewNotes: ({ count }) => `Siste ${count} notat`, }, error: { title: "Ikke funnet", notFound: "Enten er denne siden privat eller så finnes den ikke.", home: "Returner til hovedsiden", }, folderContent: { folder: "Mappe", itemsUnderFolder: ({ count }) => count === 1 ? "1 gjenstand i denne mappen." : `${count} gjenstander i denne mappen.`, }, tagContent: { tag: "Tagg", tagIndex: "Tagg Indeks", itemsUnderTag: ({ count }) => count === 1 ? "1 gjenstand med denne taggen." : `${count} gjenstander med denne taggen.`, showingFirst: ({ count }) => `Viser første ${count} tagger.`, totalTags: ({ count }) => `Fant totalt ${count} tagger.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/nl-NL.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Naamloos", description: "Geen beschrijving gegeven.", }, components: { callout: { note: "Notitie", abstract: "Samenvatting", info: "Info", todo: "Te doen", tip: "Tip", success: "Succes", question: "Vraag", warning: "Waarschuwing", failure: "Mislukking", danger: "Gevaar", bug: "Bug", example: "Voorbeeld", quote: "Citaat", }, backlinks: { title: "Backlinks", noBacklinksFound: "Geen backlinks gevonden", }, themeToggle: { lightMode: "Lichte modus", darkMode: "Donkere modus", }, readerMode: { title: "Leesmodus", }, explorer: { title: "Verkenner", }, footer: { createdWith: "Gemaakt met", }, graph: { title: "Grafiekweergave", }, recentNotes: { title: "Recente notities", seeRemainingMore: ({ remaining }) => `Zie ${remaining} meer →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Invoeging van ${targetSlug}`, linkToOriginal: "Link naar origineel", }, search: { title: "Zoeken", searchBarPlaceholder: "Doorzoek de website", }, tableOfContents: { title: "Inhoudsopgave", }, contentMeta: { readingTime: ({ minutes }) => minutes === 1 ? "1 minuut leestijd" : `${minutes} minuten leestijd`, }, }, pages: { rss: { recentNotes: "Recente notities", lastFewNotes: ({ count }) => `Laatste ${count} notities`, }, error: { title: "Niet gevonden", notFound: "Deze pagina is niet zichtbaar of bestaat niet.", home: "Keer terug naar de start pagina", }, folderContent: { folder: "Map", itemsUnderFolder: ({ count }) => count === 1 ? "1 item in deze map." : `${count} items in deze map.`, }, tagContent: { tag: "Label", tagIndex: "Label-index", itemsUnderTag: ({ count }) => count === 1 ? "1 item met dit label." : `${count} items met dit label.`, showingFirst: ({ count }) => count === 1 ? "Eerste label tonen." : `Eerste ${count} labels tonen.`, totalTags: ({ count }) => `${count} labels gevonden.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/pl-PL.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Bez nazwy", description: "Brak opisu", }, components: { callout: { note: "Notatka", abstract: "Streszczenie", info: "informacja", todo: "Do zrobienia", tip: "Wskazówka", success: "Zrobione", question: "Pytanie", warning: "Ostrzeżenie", failure: "Usterka", danger: "Niebiezpieczeństwo", bug: "Błąd w kodzie", example: "Przykład", quote: "Cytat", }, backlinks: { title: "Odnośniki zwrotne", noBacklinksFound: "Brak połączeń zwrotnych", }, themeToggle: { lightMode: "Trzyb jasny", darkMode: "Tryb ciemny", }, readerMode: { title: "Tryb czytania", }, explorer: { title: "Przeglądaj", }, footer: { createdWith: "Stworzone z użyciem", }, graph: { title: "Graf", }, recentNotes: { title: "Najnowsze notatki", seeRemainingMore: ({ remaining }) => `Zobacz ${remaining} nastepnych →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Osadzone ${targetSlug}`, linkToOriginal: "Łącze do oryginału", }, search: { title: "Szukaj", searchBarPlaceholder: "Wpisz frazę wyszukiwania", }, tableOfContents: { title: "Spis treści", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} min. czytania `, }, }, pages: { rss: { recentNotes: "Najnowsze notatki", lastFewNotes: ({ count }) => `Ostatnie ${count} notatek`, }, error: { title: "Nie znaleziono", notFound: "Ta strona jest prywatna lub nie istnieje.", home: "Powrót do strony głównej", }, folderContent: { folder: "Folder", itemsUnderFolder: ({ count }) => count === 1 ? "W tym folderze jest 1 element." : `Elementów w folderze: ${count}.`, }, tagContent: { tag: "Znacznik", tagIndex: "Spis znaczników", itemsUnderTag: ({ count }) => count === 1 ? "Oznaczony 1 element." : `Elementów z tym znacznikiem: ${count}.`, showingFirst: ({ count }) => `Pokazuje ${count} pierwszych znaczników.`, totalTags: ({ count }) => `Znalezionych wszystkich znaczników: ${count}.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/pt-BR.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Sem título", description: "Sem descrição", }, components: { callout: { note: "Nota", abstract: "Abstrato", info: "Info", todo: "Pendência", tip: "Dica", success: "Sucesso", question: "Pergunta", warning: "Aviso", failure: "Falha", danger: "Perigo", bug: "Bug", example: "Exemplo", quote: "Citação", }, backlinks: { title: "Backlinks", noBacklinksFound: "Sem backlinks encontrados", }, themeToggle: { lightMode: "Tema claro", darkMode: "Tema escuro", }, readerMode: { title: "Modo leitor", }, explorer: { title: "Explorador", }, footer: { createdWith: "Criado com", }, graph: { title: "Visão de gráfico", }, recentNotes: { title: "Notas recentes", seeRemainingMore: ({ remaining }) => `Veja mais ${remaining} →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Transcrever de ${targetSlug}`, linkToOriginal: "Link ao original", }, search: { title: "Pesquisar", searchBarPlaceholder: "Pesquisar por algo", }, tableOfContents: { title: "Sumário", }, contentMeta: { readingTime: ({ minutes }) => `Leitura de ${minutes} min`, }, }, pages: { rss: { recentNotes: "Notas recentes", lastFewNotes: ({ count }) => `Últimas ${count} notas`, }, error: { title: "Não encontrado", notFound: "Esta página é privada ou não existe.", home: "Retornar a página inicial", }, folderContent: { folder: "Arquivo", itemsUnderFolder: ({ count }) => count === 1 ? "1 item neste arquivo." : `${count} items neste arquivo.`, }, tagContent: { tag: "Tag", tagIndex: "Sumário de Tags", itemsUnderTag: ({ count }) => count === 1 ? "1 item com esta tag." : `${count} items com esta tag.`, showingFirst: ({ count }) => `Mostrando as ${count} primeiras tags.`, totalTags: ({ count }) => `Encontradas ${count} tags.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/ro-RO.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Fără titlu", description: "Nici o descriere furnizată", }, components: { callout: { note: "Notă", abstract: "Rezumat", info: "Informație", todo: "De făcut", tip: "Sfat", success: "Succes", question: "Întrebare", warning: "Avertisment", failure: "Eșec", danger: "Pericol", bug: "Bug", example: "Exemplu", quote: "Citat", }, backlinks: { title: "Legături înapoi", noBacklinksFound: "Nu s-au găsit legături înapoi", }, themeToggle: { lightMode: "Modul luminos", darkMode: "Modul întunecat", }, readerMode: { title: "Modul de citire", }, explorer: { title: "Explorator", }, footer: { createdWith: "Creat cu", }, graph: { title: "Graf", }, recentNotes: { title: "Notițe recente", seeRemainingMore: ({ remaining }) => `Vezi încă ${remaining} →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Extras din ${targetSlug}`, linkToOriginal: "Legătură către original", }, search: { title: "Căutare", searchBarPlaceholder: "Introduceți termenul de căutare...", }, tableOfContents: { title: "Cuprins", }, contentMeta: { readingTime: ({ minutes }) => minutes == 1 ? `lectură de 1 minut` : `lectură de ${minutes} minute`, }, }, pages: { rss: { recentNotes: "Notițe recente", lastFewNotes: ({ count }) => `Ultimele ${count} notițe`, }, error: { title: "Pagina nu a fost găsită", notFound: "Fie această pagină este privată, fie nu există.", home: "Reveniți la pagina de pornire", }, folderContent: { folder: "Dosar", itemsUnderFolder: ({ count }) => count === 1 ? "1 articol în acest dosar." : `${count} elemente în acest dosar.`, }, tagContent: { tag: "Etichetă", tagIndex: "Indexul etichetelor", itemsUnderTag: ({ count }) => count === 1 ? "1 articol cu această etichetă." : `${count} articole cu această etichetă.`, showingFirst: ({ count }) => `Se afișează primele ${count} etichete.`, totalTags: ({ count }) => `Au fost găsite ${count} etichete în total.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/ru-RU.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Без названия", description: "Описание отсутствует", }, components: { callout: { note: "Заметка", abstract: "Резюме", info: "Инфо", todo: "Сделать", tip: "Подсказка", success: "Успех", question: "Вопрос", warning: "Предупреждение", failure: "Неудача", danger: "Опасность", bug: "Баг", example: "Пример", quote: "Цитата", }, backlinks: { title: "Обратные ссылки", noBacklinksFound: "Обратные ссылки отсутствуют", }, themeToggle: { lightMode: "Светлый режим", darkMode: "Тёмный режим", }, readerMode: { title: "Режим чтения", }, explorer: { title: "Проводник", }, footer: { createdWith: "Создано с помощью", }, graph: { title: "Вид графа", }, recentNotes: { title: "Недавние заметки", seeRemainingMore: ({ remaining }) => `Посмотреть оставш${getForm(remaining, "уюся", "иеся", "иеся")} ${remaining} →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Переход из ${targetSlug}`, linkToOriginal: "Ссылка на оригинал", }, search: { title: "Поиск", searchBarPlaceholder: "Найти что-нибудь", }, tableOfContents: { title: "Оглавление", }, contentMeta: { readingTime: ({ minutes }) => `время чтения ~${minutes} мин.`, }, }, pages: { rss: { recentNotes: "Недавние заметки", lastFewNotes: ({ count }) => `Последн${getForm(count, "яя", "ие", "ие")} ${count} замет${getForm(count, "ка", "ки", "ок")}`, }, error: { title: "Страница не найдена", notFound: "Эта страница приватная или не существует", home: "Вернуться на главную страницу", }, folderContent: { folder: "Папка", itemsUnderFolder: ({ count }) => `в этой папке ${count} элемент${getForm(count, "", "а", "ов")}`, }, tagContent: { tag: "Тег", tagIndex: "Индекс тегов", itemsUnderTag: ({ count }) => `с этим тегом ${count} элемент${getForm(count, "", "а", "ов")}`, showingFirst: ({ count }) => `Показыва${getForm(count, "ется", "ются", "ются")} ${count} тег${getForm(count, "", "а", "ов")}`, totalTags: ({ count }) => `Всего ${count} тег${getForm(count, "", "а", "ов")}`, }, }, } as const satisfies Translation function getForm(number: number, form1: string, form2: string, form5: string): string { const remainder100 = number % 100 const remainder10 = remainder100 % 10 if (remainder100 >= 10 && remainder100 <= 20) return form5 if (remainder10 > 1 && remainder10 < 5) return form2 if (remainder10 == 1) return form1 return form5 } ================================================ FILE: quartz/i18n/locales/th-TH.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "ไม่มีชื่อ", description: "ไม่ได้ระบุคำอธิบายย่อ", }, components: { callout: { note: "หมายเหตุ", abstract: "บทคัดย่อ", info: "ข้อมูล", todo: "ต้องทำเพิ่มเติม", tip: "คำแนะนำ", success: "เรียบร้อย", question: "คำถาม", warning: "คำเตือน", failure: "ข้อผิดพลาด", danger: "อันตราย", bug: "บั๊ก", example: "ตัวอย่าง", quote: "คำพูกยกมา", }, backlinks: { title: "หน้าที่กล่าวถึง", noBacklinksFound: "ไม่มีหน้าที่โยงมาหน้านี้", }, themeToggle: { lightMode: "โหมดสว่าง", darkMode: "โหมดมืด", }, readerMode: { title: "โหมดอ่าน", }, explorer: { title: "รายการหน้า", }, footer: { createdWith: "สร้างด้วย", }, graph: { title: "มุมมองกราฟ", }, recentNotes: { title: "บันทึกล่าสุด", seeRemainingMore: ({ remaining }) => `ดูเพิ่มอีก ${remaining} รายการ →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `รวมข้ามเนื้อหาจาก ${targetSlug}`, linkToOriginal: "ดูหน้าต้นทาง", }, search: { title: "ค้นหา", searchBarPlaceholder: "ค้นหาบางอย่าง", }, tableOfContents: { title: "สารบัญ", }, contentMeta: { readingTime: ({ minutes }) => `อ่านราว ${minutes} นาที`, }, }, pages: { rss: { recentNotes: "บันทึกล่าสุด", lastFewNotes: ({ count }) => `${count} บันทึกล่าสุด`, }, error: { title: "ไม่มีหน้านี้", notFound: "หน้านี้อาจตั้งค่าเป็นส่วนตัวหรือยังไม่ถูกสร้าง", home: "กลับหน้าหลัก", }, folderContent: { folder: "โฟลเดอร์", itemsUnderFolder: ({ count }) => `มี ${count} รายการในโฟลเดอร์นี้`, }, tagContent: { tag: "แท็ก", tagIndex: "แท็กทั้งหมด", itemsUnderTag: ({ count }) => `มี ${count} รายการในแท็กนี้`, showingFirst: ({ count }) => `แสดง ${count} แท็กแรก`, totalTags: ({ count }) => `มีทั้งหมด ${count} แท็ก`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/tr-TR.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "İsimsiz", description: "Herhangi bir açıklama eklenmedi", }, components: { callout: { note: "Not", abstract: "Özet", info: "Bilgi", todo: "Yapılacaklar", tip: "İpucu", success: "Başarılı", question: "Soru", warning: "Uyarı", failure: "Başarısız", danger: "Tehlike", bug: "Hata", example: "Örnek", quote: "Alıntı", }, backlinks: { title: "Backlinkler", noBacklinksFound: "Backlink bulunamadı", }, themeToggle: { lightMode: "Açık mod", darkMode: "Koyu mod", }, readerMode: { title: "Okuma modu", }, explorer: { title: "Gezgin", }, footer: { createdWith: "Şununla oluşturuldu", }, graph: { title: "Grafik Görünümü", }, recentNotes: { title: "Son Notlar", seeRemainingMore: ({ remaining }) => `${remaining} tane daha gör →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `${targetSlug} sayfasından alıntı`, linkToOriginal: "Orijinal bağlantı", }, search: { title: "Arama", searchBarPlaceholder: "Bir şey arayın", }, tableOfContents: { title: "İçindekiler", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} dakika okuma süresi`, }, }, pages: { rss: { recentNotes: "Son notlar", lastFewNotes: ({ count }) => `Son ${count} not`, }, error: { title: "Bulunamadı", notFound: "Bu sayfa ya özel ya da mevcut değil.", home: "Anasayfaya geri dön", }, folderContent: { folder: "Klasör", itemsUnderFolder: ({ count }) => count === 1 ? "Bu klasör altında 1 öğe." : `Bu klasör altındaki ${count} öğe.`, }, tagContent: { tag: "Etiket", tagIndex: "Etiket Sırası", itemsUnderTag: ({ count }) => count === 1 ? "Bu etikete sahip 1 öğe." : `Bu etiket altındaki ${count} öğe.`, showingFirst: ({ count }) => `İlk ${count} etiket gösteriliyor.`, totalTags: ({ count }) => `Toplam ${count} adet etiket bulundu.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/uk-UA.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Без назви", description: "Опис не надано", }, components: { callout: { note: "Примітка", abstract: "Абстракт", info: "Інформація", todo: "Завдання", tip: "Порада", success: "Успіх", question: "Питання", warning: "Попередження", failure: "Невдача", danger: "Небезпека", bug: "Баг", example: "Приклад", quote: "Цитата", }, backlinks: { title: "Зворотні посилання", noBacklinksFound: "Зворотних посилань не знайдено", }, themeToggle: { lightMode: "Світлий режим", darkMode: "Темний режим", }, readerMode: { title: "Режим читання", }, explorer: { title: "Провідник", }, footer: { createdWith: "Створено за допомогою", }, graph: { title: "Вигляд графа", }, recentNotes: { title: "Останні нотатки", seeRemainingMore: ({ remaining }) => `Переглянути ще ${remaining} →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Видобуто з ${targetSlug}`, linkToOriginal: "Посилання на оригінал", }, search: { title: "Пошук", searchBarPlaceholder: "Шукати щось", }, tableOfContents: { title: "Зміст", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} хв читання`, }, }, pages: { rss: { recentNotes: "Останні нотатки", lastFewNotes: ({ count }) => `Останні нотатки: ${count}`, }, error: { title: "Не знайдено", notFound: "Ця сторінка або приватна, або не існує.", home: "Повернутися на головну сторінку", }, folderContent: { folder: "Тека", itemsUnderFolder: ({ count }) => count === 1 ? "У цій теці 1 елемент." : `Елементів у цій теці: ${count}.`, }, tagContent: { tag: "Мітка", tagIndex: "Індекс мітки", itemsUnderTag: ({ count }) => count === 1 ? "1 елемент з цією міткою." : `Елементів з цією міткою: ${count}.`, showingFirst: ({ count }) => `Показ перших ${count} міток.`, totalTags: ({ count }) => `Всього знайдено міток: ${count}.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/vi-VN.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "Không có tiêu đề", description: "Không có mô tả", }, components: { callout: { note: "Ghi chú", abstract: "Tổng quan", info: "Thông tin", todo: "Cần phải làm", tip: "Gợi ý", success: "Thành công", question: "Câu hỏi", warning: "Cảnh báo", failure: "Thất bại", danger: "Nguy hiểm", bug: "Lỗi", example: "Ví dụ", quote: "Trích dẫn", }, backlinks: { title: "Liên kết ngược", noBacklinksFound: "Không có liên kết ngược nào", }, themeToggle: { lightMode: "Chế độ sáng", darkMode: "Chế độ tối", }, readerMode: { title: "Chế độ đọc", }, explorer: { title: "Nội dung", }, footer: { createdWith: "Được tạo bằng", }, graph: { title: "Sơ đồ", }, recentNotes: { title: "Ghi chú gần đây", seeRemainingMore: ({ remaining }) => `Xem thêm ${remaining} ghi chú →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `Trích dẫn toàn bộ từ ${targetSlug}`, linkToOriginal: "Xem trang gốc", }, search: { title: "Tìm", searchBarPlaceholder: "Tìm kiếm thông tin", }, tableOfContents: { title: "Mục lục", }, contentMeta: { readingTime: ({ minutes }) => `${minutes} phút đọc`, }, }, pages: { rss: { recentNotes: "Ghi chú gần đây", lastFewNotes: ({ count }) => `${count} Trang gần đây`, }, error: { title: "Không tìm thấy", notFound: "Trang này riêng tư hoặc không tồn tại.", home: "Về trang chủ", }, folderContent: { folder: "Thư mục", itemsUnderFolder: ({ count }) => `Có ${count} trang trong thư mục này.`, }, tagContent: { tag: "Thẻ", tagIndex: "Danh sách thẻ", itemsUnderTag: ({ count }) => `Có ${count} trang gắn thẻ này.`, showingFirst: ({ count }) => `Đang hiển thị ${count} trang đầu tiên.`, totalTags: ({ count }) => `Có tổng cộng ${count} thẻ.`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/zh-CN.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "无题", description: "无描述", }, components: { callout: { note: "笔记", abstract: "摘要", info: "提示", todo: "待办", tip: "提示", success: "成功", question: "问题", warning: "警告", failure: "失败", danger: "危险", bug: "错误", example: "示例", quote: "引用", }, backlinks: { title: "反向链接", noBacklinksFound: "无法找到反向链接", }, themeToggle: { lightMode: "亮色模式", darkMode: "暗色模式", }, readerMode: { title: "阅读模式", }, explorer: { title: "探索", }, footer: { createdWith: "Created with", }, graph: { title: "关系图谱", }, recentNotes: { title: "最近的笔记", seeRemainingMore: ({ remaining }) => `查看更多${remaining}篇笔记 →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `包含${targetSlug}`, linkToOriginal: "指向原始笔记的链接", }, search: { title: "搜索", searchBarPlaceholder: "搜索些什么", }, tableOfContents: { title: "目录", }, contentMeta: { readingTime: ({ minutes }) => `${minutes}分钟阅读`, }, }, pages: { rss: { recentNotes: "最近的笔记", lastFewNotes: ({ count }) => `最近的${count}条笔记`, }, error: { title: "无法找到", notFound: "私有笔记或笔记不存在。", home: "返回首页", }, folderContent: { folder: "文件夹", itemsUnderFolder: ({ count }) => `此文件夹下有${count}条笔记。`, }, tagContent: { tag: "标签", tagIndex: "标签索引", itemsUnderTag: ({ count }) => `此标签下有${count}条笔记。`, showingFirst: ({ count }) => `显示前${count}个标签。`, totalTags: ({ count }) => `总共有${count}个标签。`, }, }, } as const satisfies Translation ================================================ FILE: quartz/i18n/locales/zh-TW.ts ================================================ import { Translation } from "./definition" export default { propertyDefaults: { title: "無題", description: "無描述", }, components: { callout: { note: "筆記", abstract: "摘要", info: "提示", todo: "待辦", tip: "提示", success: "成功", question: "問題", warning: "警告", failure: "失敗", danger: "危險", bug: "錯誤", example: "範例", quote: "引用", }, backlinks: { title: "反向連結", noBacklinksFound: "無法找到反向連結", }, themeToggle: { lightMode: "亮色模式", darkMode: "暗色模式", }, readerMode: { title: "閱讀模式", }, explorer: { title: "探索", }, footer: { createdWith: "Created with", }, graph: { title: "關係圖譜", }, recentNotes: { title: "最近的筆記", seeRemainingMore: ({ remaining }) => `查看更多 ${remaining} 篇筆記 →`, }, transcludes: { transcludeOf: ({ targetSlug }) => `包含 ${targetSlug}`, linkToOriginal: "指向原始筆記的連結", }, search: { title: "搜尋", searchBarPlaceholder: "搜尋些什麼", }, tableOfContents: { title: "目錄", }, contentMeta: { readingTime: ({ minutes }) => `閱讀時間約 ${minutes} 分鐘`, }, }, pages: { rss: { recentNotes: "最近的筆記", lastFewNotes: ({ count }) => `最近的 ${count} 條筆記`, }, error: { title: "無法找到", notFound: "私人筆記或筆記不存在。", home: "返回首頁", }, folderContent: { folder: "資料夾", itemsUnderFolder: ({ count }) => `此資料夾下有 ${count} 條筆記。`, }, tagContent: { tag: "標籤", tagIndex: "標籤索引", itemsUnderTag: ({ count }) => `此標籤下有 ${count} 條筆記。`, showingFirst: ({ count }) => `顯示前 ${count} 個標籤。`, totalTags: ({ count }) => `總共有 ${count} 個標籤。`, }, }, } as const satisfies Translation ================================================ FILE: quartz/plugins/emitters/404.tsx ================================================ import { QuartzEmitterPlugin } from "../types" import { QuartzComponentProps } from "../../components/types" import BodyConstructor from "../../components/Body" import { pageResources, renderPage } from "../../components/renderPage" import { FullPageLayout } from "../../cfg" import { FullSlug } from "../../util/path" import { sharedPageComponents } from "../../../quartz.layout" import { NotFound } from "../../components" import { defaultProcessedContent } from "../vfile" import { write } from "./helpers" import { i18n } from "../../i18n" export const NotFoundPage: QuartzEmitterPlugin = () => { const opts: FullPageLayout = { ...sharedPageComponents, pageBody: NotFound(), beforeBody: [], left: [], right: [], } const { head: Head, pageBody, footer: Footer } = opts const Body = BodyConstructor() return { name: "404Page", getQuartzComponents() { return [Head, Body, pageBody, Footer] }, async *emit(ctx, _content, resources) { const cfg = ctx.cfg.configuration const slug = "404" as FullSlug const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) const path = url.pathname as FullSlug const notFound = i18n(cfg.locale).pages.error.title const [tree, vfile] = defaultProcessedContent({ slug, text: notFound, description: notFound, frontmatter: { title: notFound, tags: [] }, }) const externalResources = pageResources(path, resources) const componentData: QuartzComponentProps = { ctx, fileData: vfile.data, externalResources, cfg, children: [], tree, allFiles: [], } yield write({ ctx, content: renderPage(cfg, slug, componentData, opts, externalResources), slug, ext: ".html", }) }, async *partialEmit() {}, } } ================================================ FILE: quartz/plugins/emitters/aliases.ts ================================================ import { FullSlug, isRelativeURL, resolveRelative, simplifySlug } from "../../util/path" import { QuartzEmitterPlugin } from "../types" import { write } from "./helpers" import { BuildCtx } from "../../util/ctx" import { VFile } from "vfile" import path from "path" async function* processFile(ctx: BuildCtx, file: VFile) { const ogSlug = simplifySlug(file.data.slug!) for (const aliasTarget of file.data.aliases ?? []) { const aliasTargetSlug = ( isRelativeURL(aliasTarget) ? path.normalize(path.join(ogSlug, "..", aliasTarget)) : aliasTarget ) as FullSlug const redirUrl = resolveRelative(aliasTargetSlug, ogSlug) yield write({ ctx, content: ` ${ogSlug} `, slug: aliasTargetSlug, ext: ".html", }) } } export const AliasRedirects: QuartzEmitterPlugin = () => ({ name: "AliasRedirects", async *emit(ctx, content) { for (const [_tree, file] of content) { yield* processFile(ctx, file) } }, async *partialEmit(ctx, _content, _resources, changeEvents) { for (const changeEvent of changeEvents) { if (!changeEvent.file) continue if (changeEvent.type === "add" || changeEvent.type === "change") { // add new ones if this file still exists yield* processFile(ctx, changeEvent.file) } } }, }) ================================================ FILE: quartz/plugins/emitters/assets.ts ================================================ import { FilePath, joinSegments, slugifyFilePath } from "../../util/path" import { QuartzEmitterPlugin } from "../types" import path from "path" import fs from "fs" import { glob } from "../../util/glob" import { Argv } from "../../util/ctx" import { QuartzConfig } from "../../cfg" const filesToCopy = async (argv: Argv, cfg: QuartzConfig) => { // glob all non MD files in content folder and copy it over return await glob("**", argv.directory, ["**/*.md", ...cfg.configuration.ignorePatterns]) } const copyFile = async (argv: Argv, fp: FilePath) => { const src = joinSegments(argv.directory, fp) as FilePath const name = slugifyFilePath(fp) const dest = joinSegments(argv.output, name) as FilePath // ensure dir exists const dir = path.dirname(dest) as FilePath await fs.promises.mkdir(dir, { recursive: true }) await fs.promises.copyFile(src, dest) return dest } export const Assets: QuartzEmitterPlugin = () => { return { name: "Assets", async *emit({ argv, cfg }) { const fps = await filesToCopy(argv, cfg) for (const fp of fps) { yield copyFile(argv, fp) } }, async *partialEmit(ctx, _content, _resources, changeEvents) { for (const changeEvent of changeEvents) { const ext = path.extname(changeEvent.path) if (ext === ".md") continue if (changeEvent.type === "add" || changeEvent.type === "change") { yield copyFile(ctx.argv, changeEvent.path) } else if (changeEvent.type === "delete") { const name = slugifyFilePath(changeEvent.path) const dest = joinSegments(ctx.argv.output, name) as FilePath await fs.promises.unlink(dest) } } }, } } ================================================ FILE: quartz/plugins/emitters/cname.ts ================================================ import { QuartzEmitterPlugin } from "../types" import { write } from "./helpers" import { styleText } from "util" import { FullSlug } from "../../util/path" export function extractDomainFromBaseUrl(baseUrl: string) { const url = new URL(`https://${baseUrl}`) return url.hostname } export const CNAME: QuartzEmitterPlugin = () => ({ name: "CNAME", async emit(ctx) { if (!ctx.cfg.configuration.baseUrl) { console.warn( styleText("yellow", "CNAME emitter requires `baseUrl` to be set in your configuration"), ) return [] } const content = extractDomainFromBaseUrl(ctx.cfg.configuration.baseUrl) if (!content) { return [] } const path = await write({ ctx, content, slug: "CNAME" as FullSlug, ext: "", }) return [path] }, async *partialEmit() {}, }) ================================================ FILE: quartz/plugins/emitters/componentResources.ts ================================================ import { FullSlug, joinSegments } from "../../util/path" import { QuartzEmitterPlugin } from "../types" // @ts-ignore import spaRouterScript from "../../components/scripts/spa.inline" // @ts-ignore import popoverScript from "../../components/scripts/popover.inline" import styles from "../../styles/custom.scss" import popoverStyle from "../../components/styles/popover.scss" import { BuildCtx } from "../../util/ctx" import { QuartzComponent } from "../../components/types" import { googleFontHref, googleFontSubsetHref, joinStyles, processGoogleFonts, } from "../../util/theme" import { Features, transform } from "lightningcss" import { transform as transpile } from "esbuild" import { write } from "./helpers" type ComponentResources = { css: string[] beforeDOMLoaded: string[] afterDOMLoaded: string[] } function getComponentResources(ctx: BuildCtx): ComponentResources { const allComponents: Set = new Set() for (const emitter of ctx.cfg.plugins.emitters) { const components = emitter.getQuartzComponents?.(ctx) ?? [] for (const component of components) { allComponents.add(component) } } const componentResources = { css: new Set(), beforeDOMLoaded: new Set(), afterDOMLoaded: new Set(), } function normalizeResource(resource: string | string[] | undefined): string[] { if (!resource) return [] if (Array.isArray(resource)) return resource return [resource] } for (const component of allComponents) { const { css, beforeDOMLoaded, afterDOMLoaded } = component const normalizedCss = normalizeResource(css) const normalizedBeforeDOMLoaded = normalizeResource(beforeDOMLoaded) const normalizedAfterDOMLoaded = normalizeResource(afterDOMLoaded) normalizedCss.forEach((c) => componentResources.css.add(c)) normalizedBeforeDOMLoaded.forEach((b) => componentResources.beforeDOMLoaded.add(b)) normalizedAfterDOMLoaded.forEach((a) => componentResources.afterDOMLoaded.add(a)) } return { css: [...componentResources.css], beforeDOMLoaded: [...componentResources.beforeDOMLoaded], afterDOMLoaded: [...componentResources.afterDOMLoaded], } } async function joinScripts(scripts: string[]): Promise { // wrap with iife to prevent scope collision const script = scripts.map((script) => `(function () {${script}})();`).join("\n") // minify with esbuild const res = await transpile(script, { minify: true, }) return res.code } function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentResources) { const cfg = ctx.cfg.configuration // popovers if (cfg.enablePopovers) { componentResources.afterDOMLoaded.push(popoverScript) componentResources.css.push(popoverStyle) } if (cfg.analytics?.provider === "google") { const tagId = cfg.analytics.tagId componentResources.afterDOMLoaded.push(` const gtagScript = document.createElement('script'); gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=${tagId}'; gtagScript.defer = true; gtagScript.onload = () => { window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', '${tagId}', { send_page_view: false }); gtag('event', 'page_view', { page_title: document.title, page_location: location.href }); document.addEventListener('nav', () => { gtag('event', 'page_view', { page_title: document.title, page_location: location.href }); }); }; document.head.appendChild(gtagScript); `) } else if (cfg.analytics?.provider === "plausible") { const plausibleHost = cfg.analytics.host ?? "https://plausible.io" componentResources.afterDOMLoaded.push(` const plausibleScript = document.createElement('script'); plausibleScript.src = '${plausibleHost}/js/script.manual.js'; plausibleScript.setAttribute('data-domain', location.hostname); plausibleScript.defer = true; plausibleScript.onload = () => { window.plausible = window.plausible || function () { (window.plausible.q = window.plausible.q || []).push(arguments); }; plausible('pageview'); document.addEventListener('nav', () => { plausible('pageview'); }); }; document.head.appendChild(plausibleScript); `) } else if (cfg.analytics?.provider === "umami") { componentResources.afterDOMLoaded.push(` const umamiScript = document.createElement("script"); umamiScript.src = "${cfg.analytics.host ?? "https://analytics.umami.is"}/script.js"; umamiScript.setAttribute("data-website-id", "${cfg.analytics.websiteId}"); umamiScript.setAttribute("data-auto-track", "true"); umamiScript.defer = true; document.head.appendChild(umamiScript); `) } else if (cfg.analytics?.provider === "goatcounter") { componentResources.afterDOMLoaded.push(` const goatcounterScriptPre = document.createElement('script'); goatcounterScriptPre.textContent = \` window.goatcounter = { no_onload: true }; \`; document.head.appendChild(goatcounterScriptPre); const endpoint = "https://${cfg.analytics.websiteId}.${cfg.analytics.host ?? "goatcounter.com"}/count"; const goatcounterScript = document.createElement('script'); goatcounterScript.src = "${cfg.analytics.scriptSrc ?? "https://gc.zgo.at/count.js"}"; goatcounterScript.defer = true; goatcounterScript.setAttribute('data-goatcounter', endpoint); goatcounterScript.onload = () => { window.goatcounter.endpoint = endpoint; goatcounter.count({ path: location.pathname }); document.addEventListener('nav', () => { goatcounter.count({ path: location.pathname }); }); }; document.head.appendChild(goatcounterScript); `) } else if (cfg.analytics?.provider === "posthog") { componentResources.afterDOMLoaded.push(` const posthogScript = document.createElement("script"); posthogScript.innerHTML= \`!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n { posthog.capture('$pageview', { path: location.pathname }); })\` document.head.appendChild(posthogScript); `) } else if (cfg.analytics?.provider === "tinylytics") { const siteId = cfg.analytics.siteId componentResources.afterDOMLoaded.push(` const tinylyticsScript = document.createElement('script'); tinylyticsScript.src = 'https://tinylytics.app/embed/${siteId}.js?spa'; tinylyticsScript.defer = true; tinylyticsScript.onload = () => { window.tinylytics.triggerUpdate(); document.addEventListener('nav', () => { window.tinylytics.triggerUpdate(); }); }; document.head.appendChild(tinylyticsScript); `) } else if (cfg.analytics?.provider === "cabin") { componentResources.afterDOMLoaded.push(` const cabinScript = document.createElement("script") cabinScript.src = "${cfg.analytics.host ?? "https://scripts.withcabin.com"}/hello.js" cabinScript.defer = true document.head.appendChild(cabinScript) `) } else if (cfg.analytics?.provider === "clarity") { componentResources.afterDOMLoaded.push(` const clarityScript = document.createElement("script") clarityScript.innerHTML= \`(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.defer=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); })(window, document, "clarity", "script", "${cfg.analytics.projectId}");\` document.head.appendChild(clarityScript) `) } else if (cfg.analytics?.provider === "matomo") { componentResources.afterDOMLoaded.push(` const matomoScript = document.createElement("script"); matomoScript.innerHTML = \` let _paq = window._paq = window._paq || []; // Track SPA navigation // https://developer.matomo.org/guides/spa-tracking document.addEventListener("nav", () => { _paq.push(['setCustomUrl', location.pathname]); _paq.push(['setDocumentTitle', document.title]); _paq.push(['trackPageView']); }); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { const u="//${cfg.analytics.host}/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', ${cfg.analytics.siteId}]); const d=document, g=d.createElement('script'), s=d.getElementsByTagName ('script')[0]; g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); \` document.head.appendChild(matomoScript); `) } else if (cfg.analytics?.provider === "vercel") { /** * script from {@link https://vercel.com/docs/analytics/quickstart?framework=html#add-the-script-tag-to-your-site|Vercel Docs} */ componentResources.beforeDOMLoaded.push(` window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); }; `) componentResources.afterDOMLoaded.push(` const vercelInsightsScript = document.createElement("script") vercelInsightsScript.src = "/_vercel/insights/script.js" vercelInsightsScript.defer = true document.head.appendChild(vercelInsightsScript) `) } else if (cfg.analytics?.provider === "rybbit") { componentResources.afterDOMLoaded.push(` const rybbitScript = document.createElement("script"); rybbitScript.src = "${cfg.analytics.host ?? "https://app.rybbit.io"}/api/script.js"; rybbitScript.setAttribute("data-site-id", "${cfg.analytics.siteId}"); rybbitScript.async = true; rybbitScript.defer = true; document.head.appendChild(rybbitScript); `) } if (cfg.enableSPA) { componentResources.afterDOMLoaded.push(spaRouterScript) } else { componentResources.afterDOMLoaded.push(` window.spaNavigate = (url, _) => window.location.assign(url) window.addCleanup = () => {} const event = new CustomEvent("nav", { detail: { url: document.body.dataset.slug } }) document.dispatchEvent(event) `) } } // This emitter should not update the `resources` parameter. If it does, partial // rebuilds may not work as expected. export const ComponentResources: QuartzEmitterPlugin = () => { return { name: "ComponentResources", async *emit(ctx, _content, _resources) { const cfg = ctx.cfg.configuration // component specific scripts and styles const componentResources = getComponentResources(ctx) let googleFontsStyleSheet = "" if (cfg.theme.fontOrigin === "local") { // let the user do it themselves in css } else if (cfg.theme.fontOrigin === "googleFonts" && !cfg.theme.cdnCaching) { // when cdnCaching is true, we link to google fonts in Head.tsx const theme = ctx.cfg.configuration.theme const response = await fetch(googleFontHref(theme)) googleFontsStyleSheet = await response.text() if (theme.typography.title) { const title = ctx.cfg.configuration.pageTitle const response = await fetch(googleFontSubsetHref(theme, title)) googleFontsStyleSheet += `\n${await response.text()}` } if (!cfg.baseUrl) { throw new Error( "baseUrl must be defined when using Google Fonts without cfg.theme.cdnCaching", ) } const { processedStylesheet, fontFiles } = await processGoogleFonts( googleFontsStyleSheet, cfg.baseUrl, ) googleFontsStyleSheet = processedStylesheet // Download and save font files for (const fontFile of fontFiles) { const res = await fetch(fontFile.url) if (!res.ok) { throw new Error(`Failed to fetch font ${fontFile.filename}`) } const buf = await res.arrayBuffer() yield write({ ctx, slug: joinSegments("static", "fonts", fontFile.filename) as FullSlug, ext: `.${fontFile.extension}`, content: Buffer.from(buf), }) } } // important that this goes *after* component scripts // as the "nav" event gets triggered here and we should make sure // that everyone else had the chance to register a listener for it addGlobalPageResources(ctx, componentResources) const stylesheet = joinStyles( ctx.cfg.configuration.theme, googleFontsStyleSheet, ...componentResources.css, styles, ) const [prescript, postscript] = await Promise.all([ joinScripts(componentResources.beforeDOMLoaded), joinScripts(componentResources.afterDOMLoaded), ]) yield write({ ctx, slug: "index" as FullSlug, ext: ".css", content: transform({ filename: "index.css", code: Buffer.from(stylesheet), minify: true, targets: { safari: (15 << 16) | (6 << 8), // 15.6 ios_saf: (15 << 16) | (6 << 8), // 15.6 edge: 115 << 16, firefox: 102 << 16, chrome: 109 << 16, }, include: Features.MediaQueries, }).code.toString(), }) yield write({ ctx, slug: "prescript" as FullSlug, ext: ".js", content: prescript, }) yield write({ ctx, slug: "postscript" as FullSlug, ext: ".js", content: postscript, }) }, async *partialEmit() {}, } } ================================================ FILE: quartz/plugins/emitters/contentIndex.tsx ================================================ import { Root } from "hast" import { GlobalConfiguration } from "../../cfg" import { getDate } from "../../components/Date" import { escapeHTML } from "../../util/escape" import { FilePath, FullSlug, SimpleSlug, joinSegments, simplifySlug } from "../../util/path" import { QuartzEmitterPlugin } from "../types" import { toHtml } from "hast-util-to-html" import { write } from "./helpers" import { i18n } from "../../i18n" export type ContentIndexMap = Map export type ContentDetails = { slug: FullSlug filePath: FilePath title: string links: SimpleSlug[] tags: string[] content: string richContent?: string date?: Date description?: string } interface Options { enableSiteMap: boolean enableRSS: boolean rssLimit?: number rssFullHtml: boolean rssSlug: string includeEmptyFiles: boolean } const defaultOptions: Options = { enableSiteMap: true, enableRSS: true, rssLimit: 10, rssFullHtml: false, rssSlug: "index", includeEmptyFiles: true, } function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndexMap): string { const base = cfg.baseUrl ?? "" const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => ` https://${joinSegments(base, encodeURI(slug))} ${content.date && `${content.date.toISOString()}`} ` const urls = Array.from(idx) .map(([slug, content]) => createURLEntry(simplifySlug(slug), content)) .join("") return `${urls}` } function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndexMap, limit?: number): string { const base = cfg.baseUrl ?? "" const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => ` ${escapeHTML(content.title)} https://${joinSegments(base, encodeURI(slug))} https://${joinSegments(base, encodeURI(slug))} ${content.date?.toUTCString()} ` const items = Array.from(idx) .sort(([_, f1], [__, f2]) => { if (f1.date && f2.date) { return f2.date.getTime() - f1.date.getTime() } else if (f1.date && !f2.date) { return -1 } else if (!f1.date && f2.date) { return 1 } return f1.title.localeCompare(f2.title) }) .map(([slug, content]) => createURLEntry(simplifySlug(slug), content)) .slice(0, limit ?? idx.size) .join("") return ` ${escapeHTML(cfg.pageTitle)} https://${base} ${!!limit ? i18n(cfg.locale).pages.rss.lastFewNotes({ count: limit }) : i18n(cfg.locale).pages.rss.recentNotes} on ${escapeHTML( cfg.pageTitle, )} Quartz -- quartz.jzhao.xyz ${items} ` } export const ContentIndex: QuartzEmitterPlugin> = (opts) => { opts = { ...defaultOptions, ...opts } return { name: "ContentIndex", async *emit(ctx, content) { const cfg = ctx.cfg.configuration const linkIndex: ContentIndexMap = new Map() for (const [tree, file] of content) { const slug = file.data.slug! const date = getDate(ctx.cfg.configuration, file.data) ?? new Date() if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) { linkIndex.set(slug, { slug, filePath: file.data.relativePath!, title: file.data.frontmatter?.title!, links: file.data.links ?? [], tags: file.data.frontmatter?.tags ?? [], content: file.data.text ?? "", richContent: opts?.rssFullHtml ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true })) : undefined, date: date, description: file.data.description ?? "", }) } } if (opts?.enableSiteMap) { yield write({ ctx, content: generateSiteMap(cfg, linkIndex), slug: "sitemap" as FullSlug, ext: ".xml", }) } if (opts?.enableRSS) { yield write({ ctx, content: generateRSSFeed(cfg, linkIndex, opts.rssLimit), slug: (opts?.rssSlug ?? "index") as FullSlug, ext: ".xml", }) } const fp = joinSegments("static", "contentIndex") as FullSlug const simplifiedIndex = Object.fromEntries( Array.from(linkIndex).map(([slug, content]) => { // remove description and from content index as nothing downstream // actually uses it. we only keep it in the index as we need it // for the RSS feed delete content.description delete content.date return [slug, content] }), ) yield write({ ctx, content: JSON.stringify(simplifiedIndex), slug: fp, ext: ".json", }) }, externalResources: (ctx) => { if (opts?.enableRSS) { return { additionalHead: [ , ], } } }, } } ================================================ FILE: quartz/plugins/emitters/contentPage.tsx ================================================ import path from "path" import { QuartzEmitterPlugin } from "../types" import { QuartzComponentProps } from "../../components/types" import HeaderConstructor from "../../components/Header" import BodyConstructor from "../../components/Body" import { pageResources, renderPage } from "../../components/renderPage" import { FullPageLayout } from "../../cfg" import { pathToRoot } from "../../util/path" import { defaultContentPageLayout, sharedPageComponents } from "../../../quartz.layout" import { Content } from "../../components" import { styleText } from "util" import { write } from "./helpers" import { BuildCtx } from "../../util/ctx" import { Node } from "unist" import { StaticResources } from "../../util/resources" import { QuartzPluginData } from "../vfile" async function processContent( ctx: BuildCtx, tree: Node, fileData: QuartzPluginData, allFiles: QuartzPluginData[], opts: FullPageLayout, resources: StaticResources, ) { const slug = fileData.slug! const cfg = ctx.cfg.configuration const externalResources = pageResources(pathToRoot(slug), resources) const componentData: QuartzComponentProps = { ctx, fileData, externalResources, cfg, children: [], tree, allFiles, } const content = renderPage(cfg, slug, componentData, opts, externalResources) return write({ ctx, content, slug, ext: ".html", }) } export const ContentPage: QuartzEmitterPlugin> = (userOpts) => { const opts: FullPageLayout = { ...sharedPageComponents, ...defaultContentPageLayout, pageBody: Content(), ...userOpts, } const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts const Header = HeaderConstructor() const Body = BodyConstructor() return { name: "ContentPage", getQuartzComponents() { return [ Head, Header, Body, ...header, ...beforeBody, pageBody, ...afterBody, ...left, ...right, Footer, ] }, async *emit(ctx, content, resources) { const allFiles = content.map((c) => c[1].data) let containsIndex = false for (const [tree, file] of content) { const slug = file.data.slug! if (slug === "index") { containsIndex = true } // only process home page, non-tag pages, and non-index pages if (slug.endsWith("/index") || slug.startsWith("tags/")) continue yield processContent(ctx, tree, file.data, allFiles, opts, resources) } if (!containsIndex) { console.log( styleText( "yellow", `\nWarning: you seem to be missing an \`index.md\` home page file at the root of your \`${ctx.argv.directory}\` folder (\`${path.join(ctx.argv.directory, "index.md")} does not exist\`). This may cause errors when deploying.`, ), ) } }, async *partialEmit(ctx, content, resources, changeEvents) { const allFiles = content.map((c) => c[1].data) // find all slugs that changed or were added const changedSlugs = new Set() for (const changeEvent of changeEvents) { if (!changeEvent.file) continue if (changeEvent.type === "add" || changeEvent.type === "change") { changedSlugs.add(changeEvent.file.data.slug!) } } for (const [tree, file] of content) { const slug = file.data.slug! if (!changedSlugs.has(slug)) continue if (slug.endsWith("/index") || slug.startsWith("tags/")) continue yield processContent(ctx, tree, file.data, allFiles, opts, resources) } }, } } ================================================ FILE: quartz/plugins/emitters/favicon.ts ================================================ import sharp from "sharp" import { joinSegments, QUARTZ, FullSlug } from "../../util/path" import { QuartzEmitterPlugin } from "../types" import { write } from "./helpers" import { BuildCtx } from "../../util/ctx" export const Favicon: QuartzEmitterPlugin = () => ({ name: "Favicon", async *emit({ argv }) { const iconPath = joinSegments(QUARTZ, "static", "icon.png") const faviconContent = sharp(iconPath).resize(48, 48).toFormat("png") yield write({ ctx: { argv } as BuildCtx, slug: "favicon" as FullSlug, ext: ".ico", content: faviconContent, }) }, async *partialEmit() {}, }) ================================================ FILE: quartz/plugins/emitters/folderPage.tsx ================================================ import { QuartzEmitterPlugin } from "../types" import { QuartzComponentProps } from "../../components/types" import HeaderConstructor from "../../components/Header" import BodyConstructor from "../../components/Body" import { pageResources, renderPage } from "../../components/renderPage" import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile" import { FullPageLayout } from "../../cfg" import path from "path" import { FullSlug, SimpleSlug, stripSlashes, joinSegments, pathToRoot, simplifySlug, } from "../../util/path" import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout" import { FolderContent } from "../../components" import { write } from "./helpers" import { i18n, TRANSLATIONS } from "../../i18n" import { BuildCtx } from "../../util/ctx" import { StaticResources } from "../../util/resources" interface FolderPageOptions extends FullPageLayout { sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number } async function* processFolderInfo( ctx: BuildCtx, folderInfo: Record, allFiles: QuartzPluginData[], opts: FullPageLayout, resources: StaticResources, ) { for (const [folder, folderContent] of Object.entries(folderInfo) as [ SimpleSlug, ProcessedContent, ][]) { const slug = joinSegments(folder, "index") as FullSlug const [tree, file] = folderContent const cfg = ctx.cfg.configuration const externalResources = pageResources(pathToRoot(slug), resources) const componentData: QuartzComponentProps = { ctx, fileData: file.data, externalResources, cfg, children: [], tree, allFiles, } const content = renderPage(cfg, slug, componentData, opts, externalResources) yield write({ ctx, content, slug, ext: ".html", }) } } function computeFolderInfo( folders: Set, content: ProcessedContent[], locale: keyof typeof TRANSLATIONS, ): Record { // Create default folder descriptions const folderInfo: Record = Object.fromEntries( [...folders].map((folder) => [ folder, defaultProcessedContent({ slug: joinSegments(folder, "index") as FullSlug, frontmatter: { title: `${i18n(locale).pages.folderContent.folder}: ${folder}`, tags: [], }, }), ]), ) // Update with actual content if available for (const [tree, file] of content) { const slug = stripSlashes(simplifySlug(file.data.slug!)) as SimpleSlug if (folders.has(slug)) { folderInfo[slug] = [tree, file] } } return folderInfo } function _getFolders(slug: FullSlug): SimpleSlug[] { var folderName = path.dirname(slug ?? "") as SimpleSlug const parentFolderNames = [folderName] while (folderName !== ".") { folderName = path.dirname(folderName ?? "") as SimpleSlug parentFolderNames.push(folderName) } return parentFolderNames } export const FolderPage: QuartzEmitterPlugin> = (userOpts) => { const opts: FullPageLayout = { ...sharedPageComponents, ...defaultListPageLayout, pageBody: FolderContent({ sort: userOpts?.sort }), ...userOpts, } const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts const Header = HeaderConstructor() const Body = BodyConstructor() return { name: "FolderPage", getQuartzComponents() { return [ Head, Header, Body, ...header, ...beforeBody, pageBody, ...afterBody, ...left, ...right, Footer, ] }, async *emit(ctx, content, resources) { const allFiles = content.map((c) => c[1].data) const cfg = ctx.cfg.configuration const folders: Set = new Set( allFiles.flatMap((data) => { return data.slug ? _getFolders(data.slug).filter( (folderName) => folderName !== "." && folderName !== "tags", ) : [] }), ) const folderInfo = computeFolderInfo(folders, content, cfg.locale) yield* processFolderInfo(ctx, folderInfo, allFiles, opts, resources) }, async *partialEmit(ctx, content, resources, changeEvents) { const allFiles = content.map((c) => c[1].data) const cfg = ctx.cfg.configuration // Find all folders that need to be updated based on changed files const affectedFolders: Set = new Set() for (const changeEvent of changeEvents) { if (!changeEvent.file) continue const slug = changeEvent.file.data.slug! const folders = _getFolders(slug).filter( (folderName) => folderName !== "." && folderName !== "tags", ) folders.forEach((folder) => affectedFolders.add(folder)) } // If there are affected folders, rebuild their pages if (affectedFolders.size > 0) { const folderInfo = computeFolderInfo(affectedFolders, content, cfg.locale) yield* processFolderInfo(ctx, folderInfo, allFiles, opts, resources) } }, } } ================================================ FILE: quartz/plugins/emitters/helpers.ts ================================================ import path from "path" import fs from "fs" import { BuildCtx } from "../../util/ctx" import { FilePath, FullSlug, joinSegments } from "../../util/path" import { Readable } from "stream" type WriteOptions = { ctx: BuildCtx slug: FullSlug ext: `.${string}` | "" content: string | Buffer | Readable } export const write = async ({ ctx, slug, ext, content }: WriteOptions): Promise => { const pathToPage = joinSegments(ctx.argv.output, slug + ext) as FilePath const dir = path.dirname(pathToPage) await fs.promises.mkdir(dir, { recursive: true }) await fs.promises.writeFile(pathToPage, content) return pathToPage } ================================================ FILE: quartz/plugins/emitters/index.ts ================================================ export { ContentPage } from "./contentPage" export { TagPage } from "./tagPage" export { FolderPage } from "./folderPage" export { ContentIndex as ContentIndex } from "./contentIndex" export { AliasRedirects } from "./aliases" export { Assets } from "./assets" export { Static } from "./static" export { Favicon } from "./favicon" export { ComponentResources } from "./componentResources" export { NotFoundPage } from "./404" export { CNAME } from "./cname" export { CustomOgImages } from "./ogImage" ================================================ FILE: quartz/plugins/emitters/ogImage.tsx ================================================ import { QuartzEmitterPlugin } from "../types" import { i18n } from "../../i18n" import { unescapeHTML } from "../../util/escape" import { FullSlug, getFileExtension, isAbsoluteURL, joinSegments, QUARTZ } from "../../util/path" import { ImageOptions, SocialImageOptions, defaultImage, getSatoriFonts } from "../../util/og" import sharp from "sharp" import satori, { SatoriOptions } from "satori" import { loadEmoji, getIconCode } from "../../util/emoji" import { Readable } from "stream" import { write } from "./helpers" import { BuildCtx } from "../../util/ctx" import { QuartzPluginData } from "../vfile" import fs from "node:fs/promises" import { styleText } from "util" const defaultOptions: SocialImageOptions = { colorScheme: "lightMode", width: 1200, height: 630, imageStructure: defaultImage, excludeRoot: false, } /** * Generates social image (OG/twitter standard) and saves it as `.webp` inside the public folder * @param opts options for generating image */ async function generateSocialImage( { cfg, description, fonts, title, fileData }: ImageOptions, userOpts: SocialImageOptions, ): Promise { const { width, height } = userOpts const iconPath = joinSegments(QUARTZ, "static", "icon.png") let iconBase64: string | undefined = undefined try { const iconData = await fs.readFile(iconPath) iconBase64 = `data:image/png;base64,${iconData.toString("base64")}` } catch (err) { console.warn(styleText("yellow", `Warning: Could not find icon at ${iconPath}`)) } const imageComponent = userOpts.imageStructure({ cfg, userOpts, title, description, fonts, fileData, iconBase64, }) const svg = await satori(imageComponent, { width, height, fonts, loadAdditionalAsset: async (languageCode: string, segment: string) => { if (languageCode === "emoji") { return await loadEmoji(getIconCode(segment)) } return languageCode }, }) return sharp(Buffer.from(svg)).webp({ quality: 40 }) } async function processOgImage( ctx: BuildCtx, fileData: QuartzPluginData, fonts: SatoriOptions["fonts"], fullOptions: SocialImageOptions, ) { const cfg = ctx.cfg.configuration const slug = fileData.slug! const titleSuffix = cfg.pageTitleSuffix ?? "" const title = (fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title) + titleSuffix const description = fileData.frontmatter?.socialDescription ?? fileData.frontmatter?.description ?? unescapeHTML(fileData.description?.trim() ?? i18n(cfg.locale).propertyDefaults.description) const stream = await generateSocialImage( { title, description, fonts, cfg, fileData, }, fullOptions, ) return write({ ctx, content: stream, slug: `${slug}-og-image` as FullSlug, ext: ".webp", }) } export const CustomOgImagesEmitterName = "CustomOgImages" export const CustomOgImages: QuartzEmitterPlugin> = (userOpts) => { const fullOptions = { ...defaultOptions, ...userOpts } return { name: CustomOgImagesEmitterName, getQuartzComponents() { return [] }, async *emit(ctx, content, _resources) { const cfg = ctx.cfg.configuration const headerFont = cfg.theme.typography.header const bodyFont = cfg.theme.typography.body const fonts = await getSatoriFonts(headerFont, bodyFont) for (const [_tree, vfile] of content) { if (vfile.data.frontmatter?.socialImage !== undefined) continue yield processOgImage(ctx, vfile.data, fonts, fullOptions) } }, async *partialEmit(ctx, _content, _resources, changeEvents) { const cfg = ctx.cfg.configuration const headerFont = cfg.theme.typography.header const bodyFont = cfg.theme.typography.body const fonts = await getSatoriFonts(headerFont, bodyFont) // find all slugs that changed or were added for (const changeEvent of changeEvents) { if (!changeEvent.file) continue if (changeEvent.file.data.frontmatter?.socialImage !== undefined) continue if (changeEvent.type === "add" || changeEvent.type === "change") { yield processOgImage(ctx, changeEvent.file.data, fonts, fullOptions) } } }, externalResources: (ctx) => { if (!ctx.cfg.configuration.baseUrl) { return {} } const baseUrl = ctx.cfg.configuration.baseUrl return { additionalHead: [ (pageData) => { const isRealFile = pageData.filePath !== undefined let userDefinedOgImagePath = pageData.frontmatter?.socialImage if (userDefinedOgImagePath) { userDefinedOgImagePath = isAbsoluteURL(userDefinedOgImagePath) ? userDefinedOgImagePath : `https://${baseUrl}/static/${userDefinedOgImagePath}` } const generatedOgImagePath = isRealFile ? `https://${baseUrl}/${pageData.slug!}-og-image.webp` : undefined const defaultOgImagePath = `https://${baseUrl}/static/og-image.png` const ogImagePath = userDefinedOgImagePath ?? generatedOgImagePath ?? defaultOgImagePath const ogImageMimeType = `image/${getFileExtension(ogImagePath) ?? "png"}` return ( <> {!userDefinedOgImagePath && ( <> )} ) }, ], } }, } } ================================================ FILE: quartz/plugins/emitters/static.ts ================================================ import { FilePath, QUARTZ, joinSegments } from "../../util/path" import { QuartzEmitterPlugin } from "../types" import fs from "fs" import { glob } from "../../util/glob" import { dirname } from "path" export const Static: QuartzEmitterPlugin = () => ({ name: "Static", async *emit({ argv, cfg }) { const staticPath = joinSegments(QUARTZ, "static") const fps = await glob("**", staticPath, cfg.configuration.ignorePatterns) const outputStaticPath = joinSegments(argv.output, "static") await fs.promises.mkdir(outputStaticPath, { recursive: true }) for (const fp of fps) { const src = joinSegments(staticPath, fp) as FilePath const dest = joinSegments(outputStaticPath, fp) as FilePath await fs.promises.mkdir(dirname(dest), { recursive: true }) await fs.promises.copyFile(src, dest) yield dest } }, async *partialEmit() {}, }) ================================================ FILE: quartz/plugins/emitters/tagPage.tsx ================================================ import { QuartzEmitterPlugin } from "../types" import { QuartzComponentProps } from "../../components/types" import HeaderConstructor from "../../components/Header" import BodyConstructor from "../../components/Body" import { pageResources, renderPage } from "../../components/renderPage" import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile" import { FullPageLayout } from "../../cfg" import { FullSlug, getAllSegmentPrefixes, joinSegments, pathToRoot } from "../../util/path" import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout" import { TagContent } from "../../components" import { write } from "./helpers" import { i18n, TRANSLATIONS } from "../../i18n" import { BuildCtx } from "../../util/ctx" import { StaticResources } from "../../util/resources" interface TagPageOptions extends FullPageLayout { sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number } function computeTagInfo( allFiles: QuartzPluginData[], content: ProcessedContent[], locale: keyof typeof TRANSLATIONS, ): [Set, Record] { const tags: Set = new Set( allFiles.flatMap((data) => data.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes), ) // add base tag tags.add("index") const tagDescriptions: Record = Object.fromEntries( [...tags].map((tag) => { const title = tag === "index" ? i18n(locale).pages.tagContent.tagIndex : `${i18n(locale).pages.tagContent.tag}: ${tag}` return [ tag, defaultProcessedContent({ slug: joinSegments("tags", tag) as FullSlug, frontmatter: { title, tags: [] }, }), ] }), ) // Update with actual content if available for (const [tree, file] of content) { const slug = file.data.slug! if (slug.startsWith("tags/")) { const tag = slug.slice("tags/".length) if (tags.has(tag)) { tagDescriptions[tag] = [tree, file] if (file.data.frontmatter?.title === tag) { file.data.frontmatter.title = `${i18n(locale).pages.tagContent.tag}: ${tag}` } } } } return [tags, tagDescriptions] } async function processTagPage( ctx: BuildCtx, tag: string, tagContent: ProcessedContent, allFiles: QuartzPluginData[], opts: FullPageLayout, resources: StaticResources, ) { const slug = joinSegments("tags", tag) as FullSlug const [tree, file] = tagContent const cfg = ctx.cfg.configuration const externalResources = pageResources(pathToRoot(slug), resources) const componentData: QuartzComponentProps = { ctx, fileData: file.data, externalResources, cfg, children: [], tree, allFiles, } const content = renderPage(cfg, slug, componentData, opts, externalResources) return write({ ctx, content, slug: file.data.slug!, ext: ".html", }) } export const TagPage: QuartzEmitterPlugin> = (userOpts) => { const opts: FullPageLayout = { ...sharedPageComponents, ...defaultListPageLayout, pageBody: TagContent({ sort: userOpts?.sort }), ...userOpts, } const { head: Head, header, beforeBody, pageBody, afterBody, left, right, footer: Footer } = opts const Header = HeaderConstructor() const Body = BodyConstructor() return { name: "TagPage", getQuartzComponents() { return [ Head, Header, Body, ...header, ...beforeBody, pageBody, ...afterBody, ...left, ...right, Footer, ] }, async *emit(ctx, content, resources) { const allFiles = content.map((c) => c[1].data) const cfg = ctx.cfg.configuration const [tags, tagDescriptions] = computeTagInfo(allFiles, content, cfg.locale) for (const tag of tags) { yield processTagPage(ctx, tag, tagDescriptions[tag], allFiles, opts, resources) } }, async *partialEmit(ctx, content, resources, changeEvents) { const allFiles = content.map((c) => c[1].data) const cfg = ctx.cfg.configuration // Find all tags that need to be updated based on changed files const affectedTags: Set = new Set() for (const changeEvent of changeEvents) { if (!changeEvent.file) continue const slug = changeEvent.file.data.slug! // If it's a tag page itself that changed if (slug.startsWith("tags/")) { const tag = slug.slice("tags/".length) affectedTags.add(tag) } // If a file with tags changed, we need to update those tag pages const fileTags = changeEvent.file.data.frontmatter?.tags ?? [] fileTags.flatMap(getAllSegmentPrefixes).forEach((tag) => affectedTags.add(tag)) // Always update the index tag page if any file changes affectedTags.add("index") } // If there are affected tags, rebuild their pages if (affectedTags.size > 0) { // We still need to compute all tags because tag pages show all tags const [_tags, tagDescriptions] = computeTagInfo(allFiles, content, cfg.locale) for (const tag of affectedTags) { if (tagDescriptions[tag]) { yield processTagPage(ctx, tag, tagDescriptions[tag], allFiles, opts, resources) } } } }, } } ================================================ FILE: quartz/plugins/filters/draft.ts ================================================ import { QuartzFilterPlugin } from "../types" export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({ name: "RemoveDrafts", shouldPublish(_ctx, [_tree, vfile]) { const draftFlag: boolean = vfile.data?.frontmatter?.draft === true || vfile.data?.frontmatter?.draft === "true" return !draftFlag }, }) ================================================ FILE: quartz/plugins/filters/explicit.ts ================================================ import { QuartzFilterPlugin } from "../types" export const ExplicitPublish: QuartzFilterPlugin = () => ({ name: "ExplicitPublish", shouldPublish(_ctx, [_tree, vfile]) { return vfile.data?.frontmatter?.publish === true || vfile.data?.frontmatter?.publish === "true" }, }) ================================================ FILE: quartz/plugins/filters/index.ts ================================================ export { RemoveDrafts } from "./draft" export { ExplicitPublish } from "./explicit" ================================================ FILE: quartz/plugins/index.ts ================================================ import { StaticResources } from "../util/resources" import { FilePath, FullSlug } from "../util/path" import { BuildCtx } from "../util/ctx" export function getStaticResourcesFromPlugins(ctx: BuildCtx) { const staticResources: StaticResources = { css: [], js: [], additionalHead: [], } for (const transformer of [...ctx.cfg.plugins.transformers, ...ctx.cfg.plugins.emitters]) { const res = transformer.externalResources ? transformer.externalResources(ctx) : {} if (res?.js) { staticResources.js.push(...res.js) } if (res?.css) { staticResources.css.push(...res.css) } if (res?.additionalHead) { staticResources.additionalHead.push(...res.additionalHead) } } // if serving locally, listen for rebuilds and reload the page if (ctx.argv.serve) { const wsUrl = ctx.argv.remoteDevHost ? `wss://${ctx.argv.remoteDevHost}:${ctx.argv.wsPort}` : `ws://localhost:${ctx.argv.wsPort}` staticResources.js.push({ loadTime: "afterDOMReady", contentType: "inline", script: ` const socket = new WebSocket('${wsUrl}') // reload(true) ensures resources like images and scripts are fetched again in firefox socket.addEventListener('message', () => document.location.reload(true)) `, }) } return staticResources } export * from "./transformers" export * from "./filters" export * from "./emitters" declare module "vfile" { // inserted in processors.ts interface DataMap { slug: FullSlug filePath: FilePath relativePath: FilePath } } ================================================ FILE: quartz/plugins/transformers/citations.ts ================================================ import rehypeCitation from "rehype-citation" import { PluggableList } from "unified" import { visit } from "unist-util-visit" import { QuartzTransformerPlugin } from "../types" export interface Options { bibliographyFile: string suppressBibliography: boolean linkCitations: boolean csl: string } const defaultOptions: Options = { bibliographyFile: "./bibliography.bib", suppressBibliography: false, linkCitations: false, csl: "apa", } export const Citations: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "Citations", htmlPlugins(ctx) { const plugins: PluggableList = [] // per default, rehype-citations only supports en-US // see: https://github.com/timlrx/rehype-citation/issues/12 // in here there are multiple usable locales: // https://github.com/citation-style-language/locales // thus, we optimistically assume there is indeed an appropriate // locale available and simply create the lang url-string let lang: string = "en-US" if (ctx.cfg.configuration.locale !== "en-US") { lang = `https://raw.githubusercontent.com/citation-stylelanguage/locales/refs/heads/master/locales-${ctx.cfg.configuration.locale}.xml` } // Add rehype-citation to the list of plugins plugins.push([ rehypeCitation, { bibliography: opts.bibliographyFile, suppressBibliography: opts.suppressBibliography, linkCitations: opts.linkCitations, csl: opts.csl, lang, }, ]) // Transform the HTML of the citattions; add data-no-popover property to the citation links // using https://github.com/syntax-tree/unist-util-visit as they're just anochor links plugins.push(() => { return (tree, _file) => { visit(tree, "element", (node, _index, _parent) => { if (node.tagName === "a" && node.properties?.href?.startsWith("#bib")) { node.properties["data-no-popover"] = true } }) } }) return plugins }, } } ================================================ FILE: quartz/plugins/transformers/description.ts ================================================ import { Root as HTMLRoot } from "hast" import { toString } from "hast-util-to-string" import { QuartzTransformerPlugin } from "../types" import { escapeHTML } from "../../util/escape" export interface Options { descriptionLength: number maxDescriptionLength: number replaceExternalLinks: boolean } const defaultOptions: Options = { descriptionLength: 150, maxDescriptionLength: 300, replaceExternalLinks: true, } const urlRegex = new RegExp( /(https?:\/\/)?(?([\da-z\.-]+)\.([a-z\.]{2,6})(:\d+)?)(?[\/\w\.-]*)(\?[\/\w\.=&;-]*)?/, "g", ) export const Description: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "Description", htmlPlugins() { return [ () => { return async (tree: HTMLRoot, file) => { let frontMatterDescription = file.data.frontmatter?.description let text = escapeHTML(toString(tree)) if (opts.replaceExternalLinks) { frontMatterDescription = frontMatterDescription?.replace( urlRegex, "$" + "$", ) text = text.replace(urlRegex, "$" + "$") } if (frontMatterDescription) { file.data.description = frontMatterDescription file.data.text = text return } // otherwise, use the text content const desc = text const sentences = desc.replace(/\s+/g, " ").split(/\.\s/) let finalDesc = "" let sentenceIdx = 0 // Add full sentences until we exceed the guideline length while (sentenceIdx < sentences.length) { const sentence = sentences[sentenceIdx] if (!sentence) break const currentSentence = sentence.endsWith(".") ? sentence : sentence + "." const nextLength = finalDesc.length + currentSentence.length + (finalDesc ? 1 : 0) // Add the sentence if we're under the guideline length // or if this is the first sentence (always include at least one) if (nextLength <= opts.descriptionLength || sentenceIdx === 0) { finalDesc += (finalDesc ? " " : "") + currentSentence sentenceIdx++ } else { break } } // truncate to max length if necessary file.data.description = finalDesc.length > opts.maxDescriptionLength ? finalDesc.slice(0, opts.maxDescriptionLength) + "..." : finalDesc file.data.text = text } }, ] }, } } declare module "vfile" { interface DataMap { description: string text: string } } ================================================ FILE: quartz/plugins/transformers/frontmatter.ts ================================================ import matter from "gray-matter" import remarkFrontmatter from "remark-frontmatter" import { QuartzTransformerPlugin } from "../types" import yaml from "js-yaml" import toml from "toml" import { FilePath, FullSlug, getFileExtension, slugifyFilePath, slugTag } from "../../util/path" import { QuartzPluginData } from "../vfile" import { i18n } from "../../i18n" export interface Options { delimiters: string | [string, string] language: "yaml" | "toml" } const defaultOptions: Options = { delimiters: "---", language: "yaml", } function coalesceAliases(data: { [key: string]: any }, aliases: string[]) { for (const alias of aliases) { if (data[alias] !== undefined && data[alias] !== null) return data[alias] } } function coerceToArray(input: string | string[]): string[] | undefined { if (input === undefined || input === null) return undefined // coerce to array if (!Array.isArray(input)) { input = input .toString() .split(",") .map((tag: string) => tag.trim()) } // remove all non-strings return input .filter((tag: unknown) => typeof tag === "string" || typeof tag === "number") .map((tag: string | number) => tag.toString()) } function getAliasSlugs(aliases: string[]): FullSlug[] { const res: FullSlug[] = [] for (const alias of aliases) { const isMd = getFileExtension(alias) === "md" const mockFp = isMd ? alias : alias + ".md" const slug = slugifyFilePath(mockFp as FilePath) res.push(slug) } return res } export const FrontMatter: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "FrontMatter", markdownPlugins(ctx) { const { cfg, allSlugs } = ctx return [ [remarkFrontmatter, ["yaml", "toml"]], () => { return (_, file) => { const fileData = Buffer.from(file.value as Uint8Array) const { data } = matter(fileData, { ...opts, engines: { yaml: (s) => yaml.load(s, { schema: yaml.JSON_SCHEMA }) as object, toml: (s) => toml.parse(s) as object, }, }) if (data.title != null && data.title.toString() !== "") { data.title = data.title.toString() } else { data.title = file.stem ?? i18n(cfg.configuration.locale).propertyDefaults.title } const tags = coerceToArray(coalesceAliases(data, ["tags", "tag"])) if (tags) data.tags = [...new Set(tags.map((tag: string) => slugTag(tag)))] const aliases = coerceToArray(coalesceAliases(data, ["aliases", "alias"])) if (aliases) { data.aliases = aliases // frontmatter file.data.aliases = getAliasSlugs(aliases) allSlugs.push(...file.data.aliases) } if (data.permalink != null && data.permalink.toString() !== "") { data.permalink = data.permalink.toString() as FullSlug const aliases = file.data.aliases ?? [] aliases.push(data.permalink) file.data.aliases = aliases allSlugs.push(data.permalink) } const cssclasses = coerceToArray(coalesceAliases(data, ["cssclasses", "cssclass"])) if (cssclasses) data.cssclasses = cssclasses const socialImage = coalesceAliases(data, ["socialImage", "image", "cover"]) const created = coalesceAliases(data, ["created", "date"]) if (created) { data.created = created } const modified = coalesceAliases(data, [ "modified", "lastmod", "updated", "last-modified", ]) if (modified) data.modified = modified data.modified ||= created // if modified is not set, use created const published = coalesceAliases(data, ["published", "publishDate", "date"]) if (published) data.published = published if (socialImage) data.socialImage = socialImage // Remove duplicate slugs const uniqueSlugs = [...new Set(allSlugs)] allSlugs.splice(0, allSlugs.length, ...uniqueSlugs) // fill in frontmatter file.data.frontmatter = data as QuartzPluginData["frontmatter"] } }, ] }, } } declare module "vfile" { interface DataMap { aliases: FullSlug[] frontmatter: { [key: string]: unknown } & { title: string } & Partial<{ tags: string[] aliases: string[] modified: string created: string published: string description: string socialDescription: string publish: boolean | string draft: boolean | string lang: string enableToc: string cssclasses: string[] socialImage: string comments: boolean | string }> } } ================================================ FILE: quartz/plugins/transformers/gfm.ts ================================================ import remarkGfm from "remark-gfm" import smartypants from "remark-smartypants" import { QuartzTransformerPlugin } from "../types" import rehypeSlug from "rehype-slug" import rehypeAutolinkHeadings from "rehype-autolink-headings" export interface Options { enableSmartyPants: boolean linkHeadings: boolean } const defaultOptions: Options = { enableSmartyPants: true, linkHeadings: true, } export const GitHubFlavoredMarkdown: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "GitHubFlavoredMarkdown", markdownPlugins() { return opts.enableSmartyPants ? [remarkGfm, smartypants] : [remarkGfm] }, htmlPlugins() { if (opts.linkHeadings) { return [ rehypeSlug, [ rehypeAutolinkHeadings, { behavior: "append", properties: { role: "anchor", ariaHidden: true, tabIndex: -1, "data-no-popover": true, }, content: { type: "element", tagName: "svg", properties: { width: 18, height: 18, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", }, children: [ { type: "element", tagName: "path", properties: { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71", }, children: [], }, { type: "element", tagName: "path", properties: { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71", }, children: [], }, ], }, }, ], ] } else { return [] } }, } } ================================================ FILE: quartz/plugins/transformers/index.ts ================================================ export { FrontMatter } from "./frontmatter" export { GitHubFlavoredMarkdown } from "./gfm" export { Citations } from "./citations" export { CreatedModifiedDate } from "./lastmod" export { Latex } from "./latex" export { Description } from "./description" export { CrawlLinks } from "./links" export { ObsidianFlavoredMarkdown } from "./ofm" export { OxHugoFlavouredMarkdown } from "./oxhugofm" export { SyntaxHighlighting } from "./syntax" export { TableOfContents } from "./toc" export { HardLineBreaks } from "./linebreaks" export { RoamFlavoredMarkdown } from "./roam" ================================================ FILE: quartz/plugins/transformers/lastmod.ts ================================================ import fs from "fs" import { Repository } from "@napi-rs/simple-git" import { QuartzTransformerPlugin } from "../types" import path from "path" import { styleText } from "util" export interface Options { priority: ("frontmatter" | "git" | "filesystem")[] } const defaultOptions: Options = { priority: ["frontmatter", "git", "filesystem"], } // YYYY-MM-DD const iso8601DateOnlyRegex = /^\d{4}-\d{2}-\d{2}$/ function coerceDate(fp: string, d: any): Date { // check ISO8601 date-only format // we treat this one as local midnight as the normal // js date ctor treats YYYY-MM-DD as UTC midnight if (typeof d === "string" && iso8601DateOnlyRegex.test(d)) { d = `${d}T00:00:00` } const dt = new Date(d) const invalidDate = isNaN(dt.getTime()) || dt.getTime() === 0 if (invalidDate && d !== undefined) { console.log( styleText( "yellow", `\nWarning: found invalid date "${d}" in \`${fp}\`. Supported formats: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format`, ), ) } return invalidDate ? new Date() : dt } type MaybeDate = undefined | string | number export const CreatedModifiedDate: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "CreatedModifiedDate", markdownPlugins(ctx) { return [ () => { let repo: Repository | undefined = undefined let repositoryWorkdir: string if (opts.priority.includes("git")) { try { repo = Repository.discover(ctx.argv.directory) repositoryWorkdir = repo.workdir() ?? ctx.argv.directory } catch (e) { console.log( styleText( "yellow", `\nWarning: couldn't find git repository for ${ctx.argv.directory}`, ), ) } } return async (_tree, file) => { let created: MaybeDate = undefined let modified: MaybeDate = undefined let published: MaybeDate = undefined const fp = file.data.relativePath! const fullFp = file.data.filePath! for (const source of opts.priority) { if (source === "filesystem") { const st = await fs.promises.stat(fullFp) created ||= st.birthtimeMs modified ||= st.mtimeMs } else if (source === "frontmatter" && file.data.frontmatter) { created ||= file.data.frontmatter.created as MaybeDate modified ||= file.data.frontmatter.modified as MaybeDate published ||= file.data.frontmatter.published as MaybeDate } else if (source === "git" && repo) { try { const relativePath = path.relative(repositoryWorkdir, fullFp) modified ||= await repo.getFileLatestModifiedDateAsync(relativePath) } catch { console.log( styleText( "yellow", `\nWarning: ${file.data.filePath!} isn't yet tracked by git, dates will be inaccurate`, ), ) } } } file.data.dates = { created: coerceDate(fp, created), modified: coerceDate(fp, modified), published: coerceDate(fp, published), } } }, ] }, } } declare module "vfile" { interface DataMap { dates: { created: Date modified: Date published: Date } } } ================================================ FILE: quartz/plugins/transformers/latex.ts ================================================ import remarkMath from "remark-math" import rehypeKatex from "rehype-katex" import rehypeMathjax from "rehype-mathjax/svg" //@ts-ignore import rehypeTypst from "@myriaddreamin/rehype-typst" import { QuartzTransformerPlugin } from "../types" import { KatexOptions } from "katex" import { Options as MathjaxOptions } from "rehype-mathjax/svg" //@ts-ignore import { Options as TypstOptions } from "@myriaddreamin/rehype-typst" interface Options { renderEngine: "katex" | "mathjax" | "typst" customMacros: MacroType katexOptions: Omit mathJaxOptions: Omit typstOptions: TypstOptions } // mathjax macros export type Args = boolean | number | string | null interface MacroType { [key: string]: string | Args[] } export const Latex: QuartzTransformerPlugin> = (opts) => { const engine = opts?.renderEngine ?? "katex" const macros = opts?.customMacros ?? {} return { name: "Latex", markdownPlugins() { return [remarkMath] }, htmlPlugins() { switch (engine) { case "katex": { return [[rehypeKatex, { output: "html", macros, ...(opts?.katexOptions ?? {}) }]] } case "typst": { return [[rehypeTypst, opts?.typstOptions ?? {}]] } default: case "mathjax": { return [ [ rehypeMathjax, { ...(opts?.mathJaxOptions ?? {}), tex: { ...(opts?.mathJaxOptions?.tex ?? {}), macros, }, }, ], ] } } }, externalResources() { switch (engine) { case "katex": return { css: [{ content: "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" }], js: [ { // fix copy behaviour: https://github.com/KaTeX/KaTeX/blob/main/contrib/copy-tex/README.md src: "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/copy-tex.min.js", loadTime: "afterDOMReady", contentType: "external", }, ], } } }, } } ================================================ FILE: quartz/plugins/transformers/linebreaks.ts ================================================ import { QuartzTransformerPlugin } from "../types" import remarkBreaks from "remark-breaks" export const HardLineBreaks: QuartzTransformerPlugin = () => { return { name: "HardLineBreaks", markdownPlugins() { return [remarkBreaks] }, } } ================================================ FILE: quartz/plugins/transformers/links.ts ================================================ import { QuartzTransformerPlugin } from "../types" import { FullSlug, RelativeURL, SimpleSlug, TransformOptions, stripSlashes, simplifySlug, splitAnchor, transformLink, } from "../../util/path" import path from "path" import { visit } from "unist-util-visit" import isAbsoluteUrl from "is-absolute-url" import { Root } from "hast" interface Options { /** How to resolve Markdown paths */ markdownLinkResolution: TransformOptions["strategy"] /** Strips folders from a link so that it looks nice */ prettyLinks: boolean openLinksInNewTab: boolean lazyLoad: boolean externalLinkIcon: boolean } const defaultOptions: Options = { markdownLinkResolution: "absolute", prettyLinks: true, openLinksInNewTab: false, lazyLoad: false, externalLinkIcon: true, } export const CrawlLinks: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "LinkProcessing", htmlPlugins(ctx) { return [ () => { return (tree: Root, file) => { const curSlug = simplifySlug(file.data.slug!) const outgoing: Set = new Set() const transformOptions: TransformOptions = { strategy: opts.markdownLinkResolution, allSlugs: ctx.allSlugs, } visit(tree, "element", (node, _index, _parent) => { // rewrite all links if ( node.tagName === "a" && node.properties && typeof node.properties.href === "string" ) { let dest = node.properties.href as RelativeURL const classes = (node.properties.className ?? []) as string[] const isExternal = isAbsoluteUrl(dest, { httpOnly: false }) classes.push(isExternal ? "external" : "internal") if (isExternal && opts.externalLinkIcon) { node.children.push({ type: "element", tagName: "svg", properties: { "aria-hidden": "true", class: "external-icon", style: "max-width:0.8em;max-height:0.8em", viewBox: "0 0 512 512", }, children: [ { type: "element", tagName: "path", properties: { d: "M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z", }, children: [], }, ], }) } // Check if the link has alias text if ( node.children.length === 1 && node.children[0].type === "text" && node.children[0].value !== dest ) { // Add the 'alias' class if the text content is not the same as the href classes.push("alias") } node.properties.className = classes if (isExternal && opts.openLinksInNewTab) { node.properties.target = "_blank" } // don't process external links or intra-document anchors const isInternal = !( isAbsoluteUrl(dest, { httpOnly: false }) || dest.startsWith("#") ) if (isInternal) { dest = node.properties.href = transformLink( file.data.slug!, dest, transformOptions, ) // url.resolve is considered legacy // WHATWG equivalent https://nodejs.dev/en/api/v18/url/#urlresolvefrom-to const url = new URL(dest, "https://base.com/" + stripSlashes(curSlug, true)) const canonicalDest = url.pathname let [destCanonical, _destAnchor] = splitAnchor(canonicalDest) if (destCanonical.endsWith("/")) { destCanonical += "index" } // need to decodeURIComponent here as WHATWG URL percent-encodes everything const full = decodeURIComponent(stripSlashes(destCanonical, true)) as FullSlug const simple = simplifySlug(full) outgoing.add(simple) node.properties["data-slug"] = full } // rewrite link internals if prettylinks is on if ( opts.prettyLinks && isInternal && node.children.length === 1 && node.children[0].type === "text" && !node.children[0].value.startsWith("#") ) { node.children[0].value = path.basename(node.children[0].value) } } // transform all other resources that may use links if ( ["img", "video", "audio", "iframe"].includes(node.tagName) && node.properties && typeof node.properties.src === "string" ) { if (opts.lazyLoad) { node.properties.loading = "lazy" } if (!isAbsoluteUrl(node.properties.src, { httpOnly: false })) { let dest = node.properties.src as RelativeURL dest = node.properties.src = transformLink( file.data.slug!, dest, transformOptions, ) node.properties.src = dest } } }) file.data.links = [...outgoing] } }, ] }, } } declare module "vfile" { interface DataMap { links: SimpleSlug[] } } ================================================ FILE: quartz/plugins/transformers/ofm.ts ================================================ import { QuartzTransformerPlugin } from "../types" import { Root, Html, BlockContent, PhrasingContent, DefinitionContent, Paragraph, Code, } from "mdast" import { Element, Literal, Root as HtmlRoot } from "hast" import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace" import rehypeRaw from "rehype-raw" import { SKIP, visit } from "unist-util-visit" import path from "path" import { splitAnchor } from "../../util/path" import { JSResource, CSSResource } from "../../util/resources" // @ts-ignore import calloutScript from "../../components/scripts/callout.inline" // @ts-ignore import checkboxScript from "../../components/scripts/checkbox.inline" // @ts-ignore import mermaidScript from "../../components/scripts/mermaid.inline" import mermaidStyle from "../../components/styles/mermaid.inline.scss" import { FilePath, pathToRoot, slugTag, slugifyFilePath } from "../../util/path" import { toHast } from "mdast-util-to-hast" import { toHtml } from "hast-util-to-html" import { capitalize } from "../../util/lang" import { PluggableList } from "unified" export interface Options { comments: boolean highlight: boolean wikilinks: boolean callouts: boolean mermaid: boolean parseTags: boolean parseArrows: boolean parseBlockReferences: boolean enableInHtmlEmbed: boolean enableYouTubeEmbed: boolean enableVideoEmbed: boolean enableCheckbox: boolean disableBrokenWikilinks: boolean } const defaultOptions: Options = { comments: true, highlight: true, wikilinks: true, callouts: true, mermaid: true, parseTags: true, parseArrows: true, parseBlockReferences: true, enableInHtmlEmbed: false, enableYouTubeEmbed: true, enableVideoEmbed: true, enableCheckbox: false, disableBrokenWikilinks: false, } const calloutMapping = { note: "note", abstract: "abstract", summary: "abstract", tldr: "abstract", info: "info", todo: "todo", tip: "tip", hint: "tip", important: "tip", success: "success", check: "success", done: "success", question: "question", help: "question", faq: "question", warning: "warning", attention: "warning", caution: "warning", failure: "failure", missing: "failure", fail: "failure", danger: "danger", error: "danger", bug: "bug", example: "example", quote: "quote", cite: "quote", } as const const arrowMapping: Record = { "->": "→", "-->": "⇒", "=>": "⇒", "==>": "⇒", "<-": "←", "<--": "⇐", "<=": "⇐", "<==": "⇐", } function canonicalizeCallout(calloutName: string): keyof typeof calloutMapping { const normalizedCallout = calloutName.toLowerCase() as keyof typeof calloutMapping // if callout is not recognized, make it a custom one return calloutMapping[normalizedCallout] ?? calloutName } export const externalLinkRegex = /^https?:\/\//i export const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/g) // !? -> optional embedding // \[\[ -> open brace // ([^\[\]\|\#]+) -> one or more non-special characters ([,],|, or #) (name) // (#[^\[\]\|\#]+)? -> # then one or more non-special characters (heading link) // (\\?\|[^\[\]\#]+)? -> optional escape \ then | then zero or more non-special characters (alias) export const wikilinkRegex = new RegExp( /!?\[\[([^\[\]\|\#\\]+)?(#+[^\[\]\|\#\\]+)?(\\?\|[^\[\]\#]*)?\]\]/g, ) // ^\|([^\n])+\|\n(\|) -> matches the header row // ( ?:?-{3,}:? ?\|)+ -> matches the header row separator // (\|([^\n])+\|\n)+ -> matches the body rows export const tableRegex = new RegExp(/^\|([^\n])+\|\n(\|)( ?:?-{3,}:? ?\|)+\n(\|([^\n])+\|\n?)+/gm) // matches any wikilink, only used for escaping wikilinks inside tables export const tableWikilinkRegex = new RegExp(/(!?\[\[[^\]]*?\]\]|\[\^[^\]]*?\])/g) const highlightRegex = new RegExp(/==([^=]+)==/g) const commentRegex = new RegExp(/%%[\s\S]*?%%/g) // from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts const calloutRegex = new RegExp(/^\[\!([\w-]+)\|?(.+?)?\]([+-]?)/) const calloutLineRegex = new RegExp(/^> *\[\!\w+\|?.*?\][+-]?.*$/gm) // (?<=^| ) -> a lookbehind assertion, tag should start be separated by a space or be the start of the line // #(...) -> capturing group, tag itself must start with # // (?:[-_\p{L}\d\p{Z}])+ -> non-capturing group, non-empty string of (Unicode-aware) alpha-numeric characters and symbols, hyphens and/or underscores // (?:\/[-_\p{L}\d\p{Z}]+)*) -> non-capturing group, matches an arbitrary number of tag strings separated by "/" const tagRegex = new RegExp( /(?<=^| )#((?:[-_\p{L}\p{Emoji}\p{M}\d])+(?:\/[-_\p{L}\p{Emoji}\p{M}\d]+)*)/gu, ) const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/g) const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ const ytPlaylistLinkRegex = /[?&]list=([^#?&]*)/ const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/) const wikilinkImageEmbedRegex = new RegExp( /^(?(?!^\d*x?\d*$).*?)?(\|?\s*?(?\d+)(x(?\d+))?)?$/, ) export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } const mdastToHtml = (ast: PhrasingContent | Paragraph) => { const hast = toHast(ast, { allowDangerousHtml: true })! return toHtml(hast, { allowDangerousHtml: true }) } return { name: "ObsidianFlavoredMarkdown", textTransform(_ctx, src) { // do comments at text level if (opts.comments) { src = src.replace(commentRegex, "") } // pre-transform blockquotes if (opts.callouts) { src = src.replace(calloutLineRegex, (value) => { // force newline after title of callout return value + "\n> " }) } // pre-transform wikilinks (fix anchors to things that may contain illegal syntax e.g. codeblocks, latex) if (opts.wikilinks) { // replace all wikilinks inside a table first src = src.replace(tableRegex, (value) => { // escape all aliases and headers in wikilinks inside a table return value.replace(tableWikilinkRegex, (_value, raw) => { // const [raw]: (string | undefined)[] = capture let escaped = raw ?? "" escaped = escaped.replace("#", "\\#") // escape pipe characters if they are not already escaped escaped = escaped.replace(/((^|[^\\])(\\\\)*)\|/g, "$1\\|") return escaped }) }) // replace all other wikilinks src = src.replace(wikilinkRegex, (value, ...capture) => { const [rawFp, rawHeader, rawAlias]: (string | undefined)[] = capture const [fp, anchor] = splitAnchor(`${rawFp ?? ""}${rawHeader ?? ""}`) const blockRef = Boolean(rawHeader?.startsWith("#^")) ? "^" : "" const displayAnchor = anchor ? `#${blockRef}${anchor.trim().replace(/^#+/, "")}` : "" const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" const embedDisplay = value.startsWith("!") ? "!" : "" if (rawFp?.match(externalLinkRegex)) { return `${embedDisplay}[${displayAlias.replace(/^\|/, "")}](${rawFp})` } return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]` }) } return src }, markdownPlugins(ctx) { const plugins: PluggableList = [] // regex replacements plugins.push(() => { return (tree: Root, file) => { const replacements: [RegExp, string | ReplaceFunction][] = [] const base = pathToRoot(file.data.slug!) if (opts.wikilinks) { replacements.push([ wikilinkRegex, (value: string, ...capture: string[]) => { let [rawFp, rawHeader, rawAlias] = capture const fp = rawFp?.trim() ?? "" const anchor = rawHeader?.trim() ?? "" const alias: string | undefined = rawAlias?.slice(1).trim() // embed cases if (value.startsWith("!")) { const ext: string = path.extname(fp).toLowerCase() const url = slugifyFilePath(fp as FilePath) if ([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp"].includes(ext)) { const match = wikilinkImageEmbedRegex.exec(alias ?? "") const alt = match?.groups?.alt ?? "" const width = match?.groups?.width ?? "auto" const height = match?.groups?.height ?? "auto" return { type: "image", url, data: { hProperties: { width, height, alt, }, }, } } else if ([".mp4", ".webm", ".ogv", ".mov", ".mkv"].includes(ext)) { return { type: "html", value: ``, } } else if ( [".mp3", ".webm", ".wav", ".m4a", ".ogg", ".3gp", ".flac"].includes(ext) ) { return { type: "html", value: ``, } } else if ([".pdf"].includes(ext)) { return { type: "html", value: ``, } } else { const block = anchor return { type: "html", data: { hProperties: { transclude: true } }, value: `
      Transclude of ${url}${block}
      `, } } // otherwise, fall through to regular link } // treat as broken link if slug not in ctx.allSlugs if (opts.disableBrokenWikilinks) { const slug = slugifyFilePath(fp as FilePath) const exists = ctx.allSlugs && ctx.allSlugs.includes(slug) if (!exists) { return { type: "html", value: `${alias ?? fp}`, } } } // internal link const url = fp + anchor return { type: "link", url, children: [ { type: "text", value: alias ?? fp, }, ], } }, ]) } if (opts.highlight) { replacements.push([ highlightRegex, (_value: string, ...capture: string[]) => { const [inner] = capture return { type: "html", value: `${inner}`, } }, ]) } if (opts.parseArrows) { replacements.push([ arrowRegex, (value: string, ..._capture: string[]) => { const maybeArrow = arrowMapping[value] if (maybeArrow === undefined) return SKIP return { type: "html", value: `${maybeArrow}`, } }, ]) } if (opts.parseTags) { replacements.push([ tagRegex, (_value: string, tag: string) => { // Check if the tag only includes numbers and slashes if (/^[\/\d]+$/.test(tag)) { return false } tag = slugTag(tag) if (file.data.frontmatter) { const noteTags = file.data.frontmatter.tags ?? [] file.data.frontmatter.tags = [...new Set([...noteTags, tag])] } return { type: "link", url: base + `/tags/${tag}`, data: { hProperties: { className: ["tag-link"], }, }, children: [ { type: "text", value: tag, }, ], } }, ]) } if (opts.enableInHtmlEmbed) { visit(tree, "html", (node: Html) => { for (const [regex, replace] of replacements) { if (typeof replace === "string") { node.value = node.value.replace(regex, replace) } else { node.value = node.value.replace(regex, (substring: string, ...args) => { const replaceValue = replace(substring, ...args) if (typeof replaceValue === "string") { return replaceValue } else if (Array.isArray(replaceValue)) { return replaceValue.map(mdastToHtml).join("") } else if (typeof replaceValue === "object" && replaceValue !== null) { return mdastToHtml(replaceValue) } else { return substring } }) } } }) } mdastFindReplace(tree, replacements) } }) if (opts.enableVideoEmbed) { plugins.push(() => { return (tree: Root, _file) => { visit(tree, "image", (node, index, parent) => { if (parent && index != undefined && videoExtensionRegex.test(node.url)) { const newNode: Html = { type: "html", value: ``, } parent.children.splice(index, 1, newNode) return SKIP } }) } }) } if (opts.callouts) { plugins.push(() => { return (tree: Root, _file) => { visit(tree, "blockquote", (node) => { if (node.children.length === 0) { return } // find first line and callout content const [firstChild, ...calloutContent] = node.children if (firstChild.type !== "paragraph" || firstChild.children[0]?.type !== "text") { return } const text = firstChild.children[0].value const restOfTitle = firstChild.children.slice(1) const [firstLine, ...remainingLines] = text.split("\n") const remainingText = remainingLines.join("\n") const match = firstLine.match(calloutRegex) if (match && match.input) { const [calloutDirective, typeString, calloutMetaData, collapseChar] = match const calloutType = canonicalizeCallout(typeString.toLowerCase()) const collapse = collapseChar === "+" || collapseChar === "-" const defaultState = collapseChar === "-" ? "collapsed" : "expanded" const titleContent = match.input.slice(calloutDirective.length).trim() const useDefaultTitle = titleContent === "" && restOfTitle.length === 0 const titleNode: Paragraph = { type: "paragraph", children: [ { type: "text", value: useDefaultTitle ? capitalize(typeString).replace(/-/g, " ") : titleContent + " ", }, ...restOfTitle, ], } const title = mdastToHtml(titleNode) const toggleIcon = `
      ` const titleHtml: Html = { type: "html", value: `
      ${title}
      ${collapse ? toggleIcon : ""}
      `, } const blockquoteContent: (BlockContent | DefinitionContent)[] = [titleHtml] if (remainingText.length > 0) { blockquoteContent.push({ type: "paragraph", children: [ { type: "text", value: remainingText, }, ], }) } // For the rest of the MD callout elements other than the title, wrap them with // two nested HTML
      s (use some hacked mdhast component to achieve this) of // class `callout-content` and `callout-content-inner` respectively for // grid-based collapsible animation. if (calloutContent.length > 0) { node.children = [ node.children[0], { data: { hProperties: { className: ["callout-content"] }, hName: "div" }, type: "blockquote", children: [...calloutContent], }, ] } // replace first line of blockquote with title and rest of the paragraph text node.children.splice(0, 1, ...blockquoteContent) const classNames = ["callout", calloutType] if (collapse) { classNames.push("is-collapsible") } if (defaultState === "collapsed") { classNames.push("is-collapsed") } // add properties to base blockquote node.data = { hProperties: { ...(node.data?.hProperties ?? {}), className: classNames.join(" "), "data-callout": calloutType, "data-callout-fold": collapse, "data-callout-metadata": calloutMetaData, }, } } }) } }) } if (opts.mermaid) { plugins.push(() => { return (tree: Root, file) => { visit(tree, "code", (node: Code) => { if (node.lang === "mermaid") { file.data.hasMermaidDiagram = true node.data = { hProperties: { className: ["mermaid"], "data-clipboard": JSON.stringify(node.value), }, } } }) } }) } return plugins }, htmlPlugins() { const plugins: PluggableList = [rehypeRaw] if (opts.parseBlockReferences) { plugins.push(() => { const inlineTagTypes = new Set(["p", "li"]) const blockTagTypes = new Set(["blockquote"]) return (tree: HtmlRoot, file) => { file.data.blocks = {} visit(tree, "element", (node, index, parent) => { if (blockTagTypes.has(node.tagName)) { const nextChild = parent?.children.at(index! + 2) as Element if (nextChild && nextChild.tagName === "p") { const text = nextChild.children.at(0) as Literal if (text && text.value && text.type === "text") { const matches = text.value.match(blockReferenceRegex) if (matches && matches.length >= 1) { parent!.children.splice(index! + 2, 1) const block = matches[0].slice(1) if (!Object.keys(file.data.blocks!).includes(block)) { node.properties = { ...node.properties, id: block, } file.data.blocks![block] = node } } } } } else if (inlineTagTypes.has(node.tagName)) { const last = node.children.at(-1) as Literal if (last && last.value && typeof last.value === "string") { const matches = last.value.match(blockReferenceRegex) if (matches && matches.length >= 1) { last.value = last.value.slice(0, -matches[0].length) const block = matches[0].slice(1) if (last.value === "") { // this is an inline block ref but the actual block // is the previous element above it let idx = (index ?? 1) - 1 while (idx >= 0) { const element = parent?.children.at(idx) if (!element) break if (element.type !== "element") { idx -= 1 } else { if (!Object.keys(file.data.blocks!).includes(block)) { element.properties = { ...element.properties, id: block, } file.data.blocks![block] = element } return } } } else { // normal paragraph transclude if (!Object.keys(file.data.blocks!).includes(block)) { node.properties = { ...node.properties, id: block, } file.data.blocks![block] = node } } } } } }) file.data.htmlAst = tree } }) } if (opts.enableYouTubeEmbed) { plugins.push(() => { return (tree: HtmlRoot) => { visit(tree, "element", (node) => { if (node.tagName === "img" && typeof node.properties.src === "string") { const match = node.properties.src.match(ytLinkRegex) const videoId = match && match[2].length == 11 ? match[2] : null const playlistId = node.properties.src.match(ytPlaylistLinkRegex)?.[1] if (videoId) { // YouTube video (with optional playlist) node.tagName = "iframe" node.properties = { class: "external-embed youtube", allow: "fullscreen", frameborder: 0, width: "600px", src: playlistId ? `https://www.youtube.com/embed/${videoId}?list=${playlistId}` : `https://www.youtube.com/embed/${videoId}`, } } else if (playlistId) { // YouTube playlist only. node.tagName = "iframe" node.properties = { class: "external-embed youtube", allow: "fullscreen", frameborder: 0, width: "600px", src: `https://www.youtube.com/embed/videoseries?list=${playlistId}`, } } } }) } }) } if (opts.enableCheckbox) { plugins.push(() => { return (tree: HtmlRoot, _file) => { visit(tree, "element", (node) => { if (node.tagName === "input" && node.properties.type === "checkbox") { const isChecked = node.properties?.checked ?? false node.properties = { type: "checkbox", disabled: false, checked: isChecked, class: "checkbox-toggle", } } }) } }) } if (opts.mermaid) { plugins.push(() => { return (tree: HtmlRoot, _file) => { visit(tree, "element", (node: Element, _idx, parent) => { if ( node.tagName === "code" && ((node.properties?.className ?? []) as string[])?.includes("mermaid") ) { parent!.children = [ { type: "element", tagName: "button", properties: { className: ["expand-button"], "aria-label": "Expand mermaid diagram", "data-view-component": true, }, children: [ { type: "element", tagName: "svg", properties: { width: 16, height: 16, viewBox: "0 0 16 16", fill: "currentColor", }, children: [ { type: "element", tagName: "path", properties: { fillRule: "evenodd", d: "M3.72 3.72a.75.75 0 011.06 1.06L2.56 7h10.88l-2.22-2.22a.75.75 0 011.06-1.06l3.5 3.5a.75.75 0 010 1.06l-3.5 3.5a.75.75 0 11-1.06-1.06l2.22-2.22H2.56l2.22 2.22a.75.75 0 11-1.06 1.06l-3.5-3.5a.75.75 0 010-1.06l3.5-3.5z", }, children: [], }, ], }, ], }, node, { type: "element", tagName: "div", properties: { id: "mermaid-container", role: "dialog" }, children: [ { type: "element", tagName: "div", properties: { id: "mermaid-space" }, children: [ { type: "element", tagName: "div", properties: { className: ["mermaid-content"] }, children: [], }, ], }, ], }, ] } }) } }) } return plugins }, externalResources() { const js: JSResource[] = [] const css: CSSResource[] = [] if (opts.enableCheckbox) { js.push({ script: checkboxScript, loadTime: "afterDOMReady", contentType: "inline", }) } if (opts.callouts) { js.push({ script: calloutScript, loadTime: "afterDOMReady", contentType: "inline", }) } if (opts.mermaid) { js.push({ script: mermaidScript, loadTime: "afterDOMReady", contentType: "inline", moduleType: "module", }) css.push({ content: mermaidStyle, inline: true, }) } return { js, css } }, } } declare module "vfile" { interface DataMap { blocks: Record htmlAst: HtmlRoot hasMermaidDiagram: boolean | undefined } } ================================================ FILE: quartz/plugins/transformers/oxhugofm.ts ================================================ import { QuartzTransformerPlugin } from "../types" import rehypeRaw from "rehype-raw" import { PluggableList } from "unified" export interface Options { /** Replace {{ relref }} with quartz wikilinks []() */ wikilinks: boolean /** Remove pre-defined anchor (see https://ox-hugo.scripter.co/doc/anchors/) */ removePredefinedAnchor: boolean /** Remove hugo shortcode syntax */ removeHugoShortcode: boolean /** Replace
      with ![]() */ replaceFigureWithMdImg: boolean /** Replace org latex fragments with $ and $$ */ replaceOrgLatex: boolean } const defaultOptions: Options = { wikilinks: true, removePredefinedAnchor: true, removeHugoShortcode: true, replaceFigureWithMdImg: true, replaceOrgLatex: true, } const relrefRegex = new RegExp(/\[([^\]]+)\]\(\{\{< relref "([^"]+)" >\}\}\)/, "g") const predefinedHeadingIdRegex = new RegExp(/(.*) {#(?:.*)}/, "g") const hugoShortcodeRegex = new RegExp(/{{(.*)}}/, "g") const figureTagRegex = new RegExp(/< ?figure src="(.*)" ?>/, "g") // \\\\\( -> matches \\( // (.+?) -> Lazy match for capturing the equation // \\\\\) -> matches \\) const inlineLatexRegex = new RegExp(/\\\\\((.+?)\\\\\)/, "g") // (?:\\begin{equation}|\\\\\(|\\\\\[) -> start of equation // ([\s\S]*?) -> Matches the block equation // (?:\\\\\]|\\\\\)|\\end{equation}) -> end of equation const blockLatexRegex = new RegExp( /(?:\\begin{equation}|\\\\\(|\\\\\[)([\s\S]*?)(?:\\\\\]|\\\\\)|\\end{equation})/, "g", ) // \$\$[\s\S]*?\$\$ -> Matches block equations // \$.*?\$ -> Matches inline equations const quartzLatexRegex = new RegExp(/\$\$[\s\S]*?\$\$|\$.*?\$/, "g") /** * ox-hugo is an org exporter backend that exports org files to hugo-compatible * markdown in an opinionated way. This plugin adds some tweaks to the generated * markdown to make it compatible with quartz but the list of changes applied it * is not exhaustive. * */ export const OxHugoFlavouredMarkdown: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "OxHugoFlavouredMarkdown", textTransform(_ctx, src) { if (opts.wikilinks) { src = src.toString() src = src.replaceAll(relrefRegex, (_value, ...capture) => { const [text, link] = capture return `[${text}](${link})` }) } if (opts.removePredefinedAnchor) { src = src.toString() src = src.replaceAll(predefinedHeadingIdRegex, (_value, ...capture) => { const [headingText] = capture return headingText }) } if (opts.removeHugoShortcode) { src = src.toString() src = src.replaceAll(hugoShortcodeRegex, (_value, ...capture) => { const [scContent] = capture return scContent }) } if (opts.replaceFigureWithMdImg) { src = src.toString() src = src.replaceAll(figureTagRegex, (_value, ...capture) => { const [src] = capture return `![](${src})` }) } if (opts.replaceOrgLatex) { src = src.toString() src = src.replaceAll(inlineLatexRegex, (_value, ...capture) => { const [eqn] = capture return `$${eqn}$` }) src = src.replaceAll(blockLatexRegex, (_value, ...capture) => { const [eqn] = capture return `$$${eqn}$$` }) // ox-hugo escapes _ as \_ src = src.replaceAll(quartzLatexRegex, (value) => { return value.replaceAll("\\_", "_") }) } return src }, htmlPlugins() { const plugins: PluggableList = [rehypeRaw] return plugins }, } } ================================================ FILE: quartz/plugins/transformers/roam.ts ================================================ import { QuartzTransformerPlugin } from "../types" import { PluggableList } from "unified" import { visit } from "unist-util-visit" import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace" import { Root, Html, Paragraph, Text, Link, Parent } from "mdast" import { BuildVisitor } from "unist-util-visit" export interface Options { orComponent: boolean TODOComponent: boolean DONEComponent: boolean videoComponent: boolean audioComponent: boolean pdfComponent: boolean blockquoteComponent: boolean tableComponent: boolean attributeComponent: boolean } const defaultOptions: Options = { orComponent: true, TODOComponent: true, DONEComponent: true, videoComponent: true, audioComponent: true, pdfComponent: true, blockquoteComponent: true, tableComponent: true, attributeComponent: true, } const orRegex = new RegExp(/{{or:(.*?)}}/, "g") const TODORegex = new RegExp(/{{.*?\bTODO\b.*?}}/, "g") const DONERegex = new RegExp(/{{.*?\bDONE\b.*?}}/, "g") const blockquoteRegex = new RegExp(/(\[\[>\]\])\s*(.*)/, "g") const roamHighlightRegex = new RegExp(/\^\^(.+)\^\^/, "g") const roamItalicRegex = new RegExp(/__(.+)__/, "g") function isSpecialEmbed(node: Paragraph): boolean { if (node.children.length !== 2) return false const [textNode, linkNode] = node.children return ( textNode.type === "text" && textNode.value.startsWith("{{[[") && linkNode.type === "link" && linkNode.children[0].type === "text" && linkNode.children[0].value.endsWith("}}") ) } function transformSpecialEmbed(node: Paragraph, opts: Options): Html | null { const [textNode, linkNode] = node.children as [Text, Link] const embedType = textNode.value.match(/\{\{\[\[(.*?)\]\]:/)?.[1]?.toLowerCase() const url = linkNode.url.slice(0, -2) // Remove the trailing '}}' switch (embedType) { case "audio": return opts.audioComponent ? { type: "html", value: ``, } : null case "video": if (!opts.videoComponent) return null // Check if it's a YouTube video const youtubeMatch = url.match( /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/, ) if (youtubeMatch) { const videoId = youtubeMatch[1].split("&")[0] // Remove additional parameters const playlistMatch = url.match(/[?&]list=([^#\&\?]*)/) const playlistId = playlistMatch ? playlistMatch[1] : null return { type: "html", value: ``, } } else { return { type: "html", value: ``, } } case "pdf": return opts.pdfComponent ? { type: "html", value: ``, } : null default: return null } } export const RoamFlavoredMarkdown: QuartzTransformerPlugin | undefined> = ( userOpts, ) => { const opts = { ...defaultOptions, ...userOpts } return { name: "RoamFlavoredMarkdown", markdownPlugins() { const plugins: PluggableList = [] plugins.push(() => { return (tree: Root) => { const replacements: [RegExp, ReplaceFunction][] = [] // Handle special embeds (audio, video, PDF) if (opts.audioComponent || opts.videoComponent || opts.pdfComponent) { visit(tree, "paragraph", ((node: Paragraph, index: number, parent: Parent | null) => { if (isSpecialEmbed(node)) { const transformedNode = transformSpecialEmbed(node, opts) if (transformedNode && parent) { parent.children[index] = transformedNode } } }) as BuildVisitor) } // Roam italic syntax replacements.push([ roamItalicRegex, (_value: string, match: string) => ({ type: "emphasis", children: [{ type: "text", value: match }], }), ]) // Roam highlight syntax replacements.push([ roamHighlightRegex, (_value: string, inner: string) => ({ type: "html", value: `${inner}`, }), ]) if (opts.orComponent) { replacements.push([ orRegex, (match: string) => { const matchResult = match.match(/{{or:(.*?)}}/) if (matchResult === null) { return { type: "html", value: "" } } const optionsString: string = matchResult[1] const options: string[] = optionsString.split("|") const selectHtml: string = `` return { type: "html", value: selectHtml } }, ]) } if (opts.TODOComponent) { replacements.push([ TODORegex, () => ({ type: "html", value: ``, }), ]) } if (opts.DONEComponent) { replacements.push([ DONERegex, () => ({ type: "html", value: ``, }), ]) } if (opts.blockquoteComponent) { replacements.push([ blockquoteRegex, (_match: string, _marker: string, content: string) => ({ type: "html", value: `
      ${content.trim()}
      `, }), ]) } mdastFindReplace(tree, replacements) } }) return plugins }, } } ================================================ FILE: quartz/plugins/transformers/syntax.ts ================================================ import { QuartzTransformerPlugin } from "../types" import rehypePrettyCode, { Options as CodeOptions, Theme as CodeTheme } from "rehype-pretty-code" interface Theme extends Record { light: CodeTheme dark: CodeTheme } interface Options { theme?: Theme keepBackground?: boolean } const defaultOptions: Options = { theme: { light: "github-light", dark: "github-dark", }, keepBackground: false, } export const SyntaxHighlighting: QuartzTransformerPlugin> = (userOpts) => { const opts: CodeOptions = { ...defaultOptions, ...userOpts } return { name: "SyntaxHighlighting", htmlPlugins() { return [[rehypePrettyCode, opts]] }, } } ================================================ FILE: quartz/plugins/transformers/toc.ts ================================================ import { QuartzTransformerPlugin } from "../types" import { Root } from "mdast" import { visit } from "unist-util-visit" import { toString } from "mdast-util-to-string" import Slugger from "github-slugger" export interface Options { maxDepth: 1 | 2 | 3 | 4 | 5 | 6 minEntries: number showByDefault: boolean collapseByDefault: boolean } const defaultOptions: Options = { maxDepth: 3, minEntries: 1, showByDefault: true, collapseByDefault: false, } interface TocEntry { depth: number text: string slug: string // this is just the anchor (#some-slug), not the canonical slug } const slugAnchor = new Slugger() export const TableOfContents: QuartzTransformerPlugin> = (userOpts) => { const opts = { ...defaultOptions, ...userOpts } return { name: "TableOfContents", markdownPlugins() { return [ () => { return async (tree: Root, file) => { const display = file.data.frontmatter?.enableToc ?? opts.showByDefault if (display) { slugAnchor.reset() const toc: TocEntry[] = [] let highestDepth: number = opts.maxDepth visit(tree, "heading", (node) => { if (node.depth <= opts.maxDepth) { const text = toString(node) highestDepth = Math.min(highestDepth, node.depth) toc.push({ depth: node.depth, text, slug: slugAnchor.slug(text), }) } }) if (toc.length > 0 && toc.length > opts.minEntries) { file.data.toc = toc.map((entry) => ({ ...entry, depth: entry.depth - highestDepth, })) file.data.collapseToc = opts.collapseByDefault } } } }, ] }, } } declare module "vfile" { interface DataMap { toc: TocEntry[] collapseToc: boolean } } ================================================ FILE: quartz/plugins/types.ts ================================================ import { PluggableList } from "unified" import { StaticResources } from "../util/resources" import { ProcessedContent } from "./vfile" import { QuartzComponent } from "../components/types" import { FilePath } from "../util/path" import { BuildCtx } from "../util/ctx" import { VFile } from "vfile" export interface PluginTypes { transformers: QuartzTransformerPluginInstance[] filters: QuartzFilterPluginInstance[] emitters: QuartzEmitterPluginInstance[] } type OptionType = object | undefined type ExternalResourcesFn = (ctx: BuildCtx) => Partial | undefined export type QuartzTransformerPlugin = ( opts?: Options, ) => QuartzTransformerPluginInstance export type QuartzTransformerPluginInstance = { name: string textTransform?: (ctx: BuildCtx, src: string) => string markdownPlugins?: (ctx: BuildCtx) => PluggableList htmlPlugins?: (ctx: BuildCtx) => PluggableList externalResources?: ExternalResourcesFn } export type QuartzFilterPlugin = ( opts?: Options, ) => QuartzFilterPluginInstance export type QuartzFilterPluginInstance = { name: string shouldPublish(ctx: BuildCtx, content: ProcessedContent): boolean } export type ChangeEvent = { type: "add" | "change" | "delete" path: FilePath file?: VFile } export type QuartzEmitterPlugin = ( opts?: Options, ) => QuartzEmitterPluginInstance export type QuartzEmitterPluginInstance = { name: string emit: ( ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources, ) => Promise | AsyncGenerator partialEmit?: ( ctx: BuildCtx, content: ProcessedContent[], resources: StaticResources, changeEvents: ChangeEvent[], ) => Promise | AsyncGenerator | null /** * Returns the components (if any) that are used in rendering the page. * This helps Quartz optimize the page by only including necessary resources * for components that are actually used. */ getQuartzComponents?: (ctx: BuildCtx) => QuartzComponent[] externalResources?: ExternalResourcesFn } ================================================ FILE: quartz/plugins/vfile.ts ================================================ import { Root as HtmlRoot } from "hast" import { Root as MdRoot } from "mdast" import { Data, VFile } from "vfile" export type QuartzPluginData = Data export type MarkdownContent = [MdRoot, VFile] export type ProcessedContent = [HtmlRoot, VFile] export function defaultProcessedContent(vfileData: Partial): ProcessedContent { const root: HtmlRoot = { type: "root", children: [] } const vfile = new VFile("") vfile.data = vfileData return [root, vfile] } ================================================ FILE: quartz/processors/emit.ts ================================================ import { PerfTimer } from "../util/perf" import { getStaticResourcesFromPlugins } from "../plugins" import { ProcessedContent } from "../plugins/vfile" import { QuartzLogger } from "../util/log" import { trace } from "../util/trace" import { BuildCtx } from "../util/ctx" import { styleText } from "util" export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) { const { argv, cfg } = ctx const perf = new PerfTimer() const log = new QuartzLogger(ctx.argv.verbose) log.start(`Emitting files`) let emittedFiles = 0 const staticResources = getStaticResourcesFromPlugins(ctx) await Promise.all( cfg.plugins.emitters.map(async (emitter) => { try { const emitted = await emitter.emit(ctx, content, staticResources) if (Symbol.asyncIterator in emitted) { // Async generator case for await (const file of emitted) { emittedFiles++ if (ctx.argv.verbose) { console.log(`[emit:${emitter.name}] ${file}`) } else { log.updateText(`${emitter.name} -> ${styleText("gray", file)}`) } } } else { // Array case emittedFiles += emitted.length for (const file of emitted) { if (ctx.argv.verbose) { console.log(`[emit:${emitter.name}] ${file}`) } else { log.updateText(`${emitter.name} -> ${styleText("gray", file)}`) } } } } catch (err) { trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error) } }), ) log.end(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince()}`) } ================================================ FILE: quartz/processors/filter.ts ================================================ import { BuildCtx } from "../util/ctx" import { PerfTimer } from "../util/perf" import { ProcessedContent } from "../plugins/vfile" export function filterContent(ctx: BuildCtx, content: ProcessedContent[]): ProcessedContent[] { const { cfg, argv } = ctx const perf = new PerfTimer() const initialLength = content.length for (const plugin of cfg.plugins.filters) { const updatedContent = content.filter((item) => plugin.shouldPublish(ctx, item)) if (argv.verbose) { const diff = content.filter((x) => !updatedContent.includes(x)) for (const file of diff) { console.log(`[filter:${plugin.name}] ${file[1].data.slug}`) } } content = updatedContent } console.log(`Filtered out ${initialLength - content.length} files in ${perf.timeSince()}`) return content } ================================================ FILE: quartz/processors/parse.ts ================================================ import esbuild from "esbuild" import remarkParse from "remark-parse" import remarkRehype from "remark-rehype" import { Processor, unified } from "unified" import { Root as MDRoot } from "remark-parse/lib" import { Root as HTMLRoot } from "hast" import { MarkdownContent, ProcessedContent } from "../plugins/vfile" import { PerfTimer } from "../util/perf" import { read } from "to-vfile" import { FilePath, QUARTZ, slugifyFilePath } from "../util/path" import path from "path" import workerpool, { Promise as WorkerPromise } from "workerpool" import { QuartzLogger } from "../util/log" import { trace } from "../util/trace" import { BuildCtx, WorkerSerializableBuildCtx } from "../util/ctx" import { styleText } from "util" export type QuartzMdProcessor = Processor export type QuartzHtmlProcessor = Processor export function createMdProcessor(ctx: BuildCtx): QuartzMdProcessor { const transformers = ctx.cfg.plugins.transformers return ( unified() // base Markdown -> MD AST .use(remarkParse) // MD AST -> MD AST transforms .use( transformers.flatMap((plugin) => plugin.markdownPlugins?.(ctx) ?? []), ) as unknown as QuartzMdProcessor // ^ sadly the typing of `use` is not smart enough to infer the correct type from our plugin list ) } export function createHtmlProcessor(ctx: BuildCtx): QuartzHtmlProcessor { const transformers = ctx.cfg.plugins.transformers return ( unified() // MD AST -> HTML AST .use(remarkRehype, { allowDangerousHtml: true }) // HTML AST -> HTML AST transforms .use(transformers.flatMap((plugin) => plugin.htmlPlugins?.(ctx) ?? [])) ) } function* chunks(arr: T[], n: number) { for (let i = 0; i < arr.length; i += n) { yield arr.slice(i, i + n) } } async function transpileWorkerScript() { // transpile worker script const cacheFile = "./.quartz-cache/transpiled-worker.mjs" const fp = "./quartz/worker.ts" return esbuild.build({ entryPoints: [fp], outfile: path.join(QUARTZ, cacheFile), bundle: true, keepNames: true, platform: "node", format: "esm", packages: "external", sourcemap: true, sourcesContent: false, plugins: [ { name: "css-and-scripts-as-text", setup(build) { build.onLoad({ filter: /\.scss$/ }, (_) => ({ contents: "", loader: "text", })) build.onLoad({ filter: /\.inline\.(ts|js)$/ }, (_) => ({ contents: "", loader: "text", })) }, }, ], }) } export function createFileParser(ctx: BuildCtx, fps: FilePath[]) { const { argv, cfg } = ctx return async (processor: QuartzMdProcessor) => { const res: MarkdownContent[] = [] for (const fp of fps) { try { const perf = new PerfTimer() const file = await read(fp) // strip leading and trailing whitespace file.value = file.value.toString().trim() // Text -> Text transforms for (const plugin of cfg.plugins.transformers.filter((p) => p.textTransform)) { file.value = plugin.textTransform!(ctx, file.value.toString()) } // base data properties that plugins may use file.data.filePath = file.path as FilePath file.data.relativePath = path.posix.relative(argv.directory, file.path) as FilePath file.data.slug = slugifyFilePath(file.data.relativePath) const ast = processor.parse(file) const newAst = await processor.run(ast, file) res.push([newAst, file]) if (argv.verbose) { console.log(`[markdown] ${fp} -> ${file.data.slug} (${perf.timeSince()})`) } } catch (err) { trace(`\nFailed to process markdown \`${fp}\``, err as Error) } } return res } } export function createMarkdownParser(ctx: BuildCtx, mdContent: MarkdownContent[]) { return async (processor: QuartzHtmlProcessor) => { const res: ProcessedContent[] = [] for (const [ast, file] of mdContent) { try { const perf = new PerfTimer() const newAst = await processor.run(ast as MDRoot, file) res.push([newAst, file]) if (ctx.argv.verbose) { console.log(`[html] ${file.data.slug} (${perf.timeSince()})`) } } catch (err) { trace(`\nFailed to process html \`${file.data.filePath}\``, err as Error) } } return res } } const clamp = (num: number, min: number, max: number) => Math.min(Math.max(Math.round(num), min), max) export async function parseMarkdown(ctx: BuildCtx, fps: FilePath[]): Promise { const { argv } = ctx const perf = new PerfTimer() const log = new QuartzLogger(argv.verbose) // rough heuristics: 128 gives enough time for v8 to JIT and optimize parsing code paths const CHUNK_SIZE = 128 const concurrency = ctx.argv.concurrency ?? clamp(fps.length / CHUNK_SIZE, 1, 4) let res: ProcessedContent[] = [] log.start(`Parsing input files using ${concurrency} threads`) if (concurrency === 1) { try { const mdRes = await createFileParser(ctx, fps)(createMdProcessor(ctx)) res = await createMarkdownParser(ctx, mdRes)(createHtmlProcessor(ctx)) } catch (error) { log.end() throw error } } else { await transpileWorkerScript() const pool = workerpool.pool("./quartz/bootstrap-worker.mjs", { minWorkers: "max", maxWorkers: concurrency, workerType: "thread", }) const errorHandler = (err: any) => { console.error(err) process.exit(1) } const serializableCtx: WorkerSerializableBuildCtx = { buildId: ctx.buildId, argv: ctx.argv, allSlugs: ctx.allSlugs, allFiles: ctx.allFiles, incremental: ctx.incremental, } const textToMarkdownPromises: WorkerPromise[] = [] let processedFiles = 0 for (const chunk of chunks(fps, CHUNK_SIZE)) { textToMarkdownPromises.push(pool.exec("parseMarkdown", [serializableCtx, chunk])) } const mdResults: Array = await Promise.all( textToMarkdownPromises.map(async (promise) => { const result = await promise processedFiles += result.length log.updateText(`text->markdown ${styleText("gray", `${processedFiles}/${fps.length}`)}`) return result }), ).catch(errorHandler) const markdownToHtmlPromises: WorkerPromise[] = [] processedFiles = 0 for (const mdChunk of mdResults) { markdownToHtmlPromises.push(pool.exec("processHtml", [serializableCtx, mdChunk])) } const results: ProcessedContent[][] = await Promise.all( markdownToHtmlPromises.map(async (promise) => { const result = await promise processedFiles += result.length log.updateText(`markdown->html ${styleText("gray", `${processedFiles}/${fps.length}`)}`) return result }), ).catch(errorHandler) res = results.flat() await pool.terminate() } log.end(`Parsed ${res.length} Markdown files in ${perf.timeSince()}`) return res } ================================================ FILE: quartz/static/giscus/dark.css ================================================ /*! MIT License * Copyright (c) 2018 GitHub Inc. * https://github.com/primer/primitives/blob/main/LICENSE */ main { --color-prettylights-syntax-comment: #8b949e; --color-prettylights-syntax-constant: #79c0ff; --color-prettylights-syntax-entity: #d2a8ff; --color-prettylights-syntax-storage-modifier-import: #c9d1d9; --color-prettylights-syntax-entity-tag: #7ee787; --color-prettylights-syntax-keyword: #ff7b72; --color-prettylights-syntax-string: #a5d6ff; --color-prettylights-syntax-variable: #ffa657; --color-prettylights-syntax-brackethighlighter-unmatched: #f85149; --color-prettylights-syntax-invalid-illegal-text: #f0f6fc; --color-prettylights-syntax-invalid-illegal-bg: #8e1519; --color-prettylights-syntax-carriage-return-text: #f0f6fc; --color-prettylights-syntax-carriage-return-bg: #b62324; --color-prettylights-syntax-string-regexp: #7ee787; --color-prettylights-syntax-markup-list: #f2cc60; --color-prettylights-syntax-markup-heading: #1f6feb; --color-prettylights-syntax-markup-italic: #c9d1d9; --color-prettylights-syntax-markup-bold: #c9d1d9; --color-prettylights-syntax-markup-deleted-text: #ffdcd7; --color-prettylights-syntax-markup-deleted-bg: #67060c; --color-prettylights-syntax-markup-inserted-text: #aff5b4; --color-prettylights-syntax-markup-inserted-bg: #033a16; --color-prettylights-syntax-markup-changed-text: #ffdfb6; --color-prettylights-syntax-markup-changed-bg: #5a1e02; --color-prettylights-syntax-markup-ignored-text: #c9d1d9; --color-prettylights-syntax-markup-ignored-bg: #1158c7; --color-prettylights-syntax-meta-diff-range: #d2a8ff; --color-prettylights-syntax-brackethighlighter-angle: #8b949e; --color-prettylights-syntax-sublimelinter-gutter-mark: #484f58; --color-prettylights-syntax-constant-other-reference-link: #a5d6ff; --color-btn-text: #d4d4d4; /* --darkgray */ --color-btn-bg: #161618; /* --light */ --color-btn-border: rgb(240, 246, 252 / 10%); /* --dark */ --color-btn-shadow: 0 0 transparent; --color-btn-inset-shadow: 0 0 transparent; --color-btn-hover-bg: #30363d; --color-btn-hover-border: #8b949e; --color-btn-active-bg: hsl(212deg 12% 18% / 100%); --color-btn-active-border: #6e7681; --color-btn-selected-bg: #161b22; --color-btn-primary-text: #fff; --color-btn-primary-bg: #84a59d; /* --tertiary */ --color-btn-primary-border: rgb(240, 246, 252 / 10%); /* --dark */ --color-btn-primary-shadow: 0 0 transparent; --color-btn-primary-inset-shadow: 0 0 transparent; --color-btn-primary-hover-bg: #7b97aa; /* --secondary */ --color-btn-primary-hover-border: rgb(240, 246, 252 / 10%); /* --dark */ --color-btn-primary-selected-bg: #7b97aa; /* --secondary */ --color-btn-primary-selected-shadow: 0 0 transparent; --color-btn-primary-disabled-text: rgba(33, 32, 32, 0.5); --color-btn-primary-disabled-bg: rgb(35 134 54 / 60%); --color-btn-primary-disabled-border: rgb(240 246 252 / 10%); --color-action-list-item-default-hover-bg: rgb(177 186 196 / 12%); --color-segmented-control-bg: rgb(110 118 129 / 10%); --color-segmented-control-button-bg: #0d1117; --color-segmented-control-button-selected-border: #6e7681; --color-fg-default: #ebebec; /* --dark */ --color-fg-muted: #d4d4d4; /* --darkgray */ --color-fg-subtle: #d4d4d4; /* --darkgray */ --color-canvas-default: #0d1117; --color-canvas-overlay: #161b22; --color-canvas-inset: #010409; --color-canvas-subtle: #161b22; --color-border-default: #30363d; --color-border-muted: #21262d; --color-neutral-muted: rgb(110 118 129 / 40%); --color-accent-fg: #2f81f7; --color-accent-emphasis: #1f6feb; --color-accent-muted: rgb(56 139 253 / 40%); --color-accent-subtle: rgb(56 139 253 / 10%); --color-success-fg: #3fb950; --color-attention-fg: #d29922; --color-attention-muted: rgb(187 128 9 / 40%); --color-attention-subtle: rgb(187 128 9 / 15%); --color-danger-fg: #f85149; --color-danger-muted: rgb(248 81 73 / 40%); --color-danger-subtle: rgb(248 81 73 / 10%); --color-primer-shadow-inset: 0 0 transparent; --color-scale-gray-7: #21262d; --color-scale-blue-8: #0c2d6b; /*! Extensions from @primer/css/alerts/flash.scss */ --color-social-reaction-bg-hover: var(--color-scale-gray-7); --color-social-reaction-bg-reacted-hover: var(--color-scale-blue-8); } main .pagination-loader-container { background-image: url("https://github.com/images/modules/pulls/progressive-disclosure-line-dark.svg"); } main .gsc-loading-image { background-image: url("https://github.githubassets.com/images/mona-loading-dark.gif"); } ================================================ FILE: quartz/static/giscus/light.css ================================================ /*! MIT License * Copyright (c) 2018 GitHub Inc. * https://github.com/primer/primitives/blob/main/LICENSE */ main { --color-prettylights-syntax-comment: #6e7781; --color-prettylights-syntax-constant: #0550ae; --color-prettylights-syntax-entity: #8250df; --color-prettylights-syntax-storage-modifier-import: #24292f; --color-prettylights-syntax-entity-tag: #116329; --color-prettylights-syntax-keyword: #cf222e; --color-prettylights-syntax-string: #0a3069; --color-prettylights-syntax-variable: #953800; --color-prettylights-syntax-brackethighlighter-unmatched: #82071e; --color-prettylights-syntax-invalid-illegal-text: #f6f8fa; --color-prettylights-syntax-invalid-illegal-bg: #82071e; --color-prettylights-syntax-carriage-return-text: #f6f8fa; --color-prettylights-syntax-carriage-return-bg: #cf222e; --color-prettylights-syntax-string-regexp: #116329; --color-prettylights-syntax-markup-list: #3b2300; --color-prettylights-syntax-markup-heading: #0550ae; --color-prettylights-syntax-markup-italic: #24292f; --color-prettylights-syntax-markup-bold: #24292f; --color-prettylights-syntax-markup-deleted-text: #82071e; --color-prettylights-syntax-markup-deleted-bg: #ffebe9; --color-prettylights-syntax-markup-inserted-text: #116329; --color-prettylights-syntax-markup-inserted-bg: #dafbe1; --color-prettylights-syntax-markup-changed-text: #953800; --color-prettylights-syntax-markup-changed-bg: #ffd8b5; --color-prettylights-syntax-markup-ignored-text: #eaeef2; --color-prettylights-syntax-markup-ignored-bg: #0550ae; --color-prettylights-syntax-meta-diff-range: #8250df; --color-prettylights-syntax-brackethighlighter-angle: #57606a; --color-prettylights-syntax-sublimelinter-gutter-mark: #8c959f; --color-prettylights-syntax-constant-other-reference-link: #0a3069; --color-btn-text: #4e4e4e; /* --darkgray */ --color-btn-bg: #faf8f8; /* --light */ --color-btn-border: rgb(43, 43, 43 / 15%); /* --dark */ --color-btn-shadow: 0 1px 0 rgb(31 35 40 / 4%); --color-btn-inset-shadow: inset 0 1px 0 rgb(255 255 255 / 25%); --color-btn-hover-bg: #f3f4f6; --color-btn-hover-border: rgb(43, 43, 43 / 15%); /* --dark */ --color-btn-active-bg: hsl(220deg 14% 93% / 100%); --color-btn-active-border: rgb(31 35 40 / 15%); --color-btn-selected-bg: hsl(220deg 14% 94% / 100%); --color-btn-primary-text: #fff; --color-btn-primary-bg: #84a59d; /* --tertiary */ --color-btn-primary-border: rgb(43, 43, 43 / 15%); /* --dark */ --color-btn-primary-shadow: 0 1px 0 rgb(31 35 40 / 10%); --color-btn-primary-inset-shadow: inset 0 1px 0 rgb(255 255 255 / 3%); --color-btn-primary-hover-bg: #284b63; /* --secondary */ --color-btn-primary-hover-border: rgb(43, 43, 43 / 15%); /* --dark */ --color-btn-primary-selected-bg: #284b63; /* --secondary */ --color-btn-primary-selected-shadow: inset 0 1px 0 rgb(0 45 17 / 20%); --color-btn-primary-disabled-text: rgb(255 255 255 / 80%); --color-btn-primary-disabled-bg: #94d3a2; --color-btn-primary-disabled-border: rgb(31 35 40 / 15%); --color-action-list-item-default-hover-bg: rgb(208 215 222 / 32%); --color-segmented-control-bg: #eaeef2; --color-segmented-control-button-bg: #fff; --color-segmented-control-button-selected-border: #8c959f; --color-fg-default: #2b2b2b; /* --dark */ --color-fg-muted: #4e4e4e; /* --darkgray */ --color-fg-subtle: #4e4e4e; /* --darkgray */ --color-canvas-default: #fff; --color-canvas-overlay: #fff; --color-canvas-inset: #f6f8fa; --color-canvas-subtle: #f6f8fa; --color-border-default: #d0d7de; --color-border-muted: hsl(210deg 18% 87% / 100%); --color-neutral-muted: rgb(175 184 193 / 20%); --color-accent-fg: #0969da; --color-accent-emphasis: #0969da; --color-accent-muted: rgb(84 174 255 / 40%); --color-accent-subtle: #ddf4ff; --color-success-fg: #1a7f37; --color-attention-fg: #9a6700; --color-attention-muted: rgb(212 167 44 / 40%); --color-attention-subtle: #fff8c5; --color-danger-fg: #d1242f; --color-danger-muted: rgb(255 129 130 / 40%); --color-danger-subtle: #ffebe9; --color-primer-shadow-inset: inset 0 1px 0 rgb(208 215 222 / 20%); --color-scale-gray-1: #eaeef2; --color-scale-blue-1: #b6e3ff; /*! Extensions from @primer/css/alerts/flash.scss */ --color-social-reaction-bg-hover: var(--color-scale-gray-1); --color-social-reaction-bg-reacted-hover: var(--color-scale-blue-1); } main .pagination-loader-container { background-image: url("https://github.com/images/modules/pulls/progressive-disclosure-line.svg"); } main .gsc-loading-image { background-image: url("https://github.githubassets.com/images/mona-loading-default.gif"); } ================================================ FILE: quartz/styles/base.scss ================================================ @use "sass:map"; @use "./variables.scss" as *; @use "./syntax.scss"; @use "./callouts.scss"; html { scroll-behavior: smooth; text-size-adjust: none; overflow-x: hidden; width: 100vw; @media all and ($mobile) { scroll-padding-top: 4rem; } } body { margin: 0; box-sizing: border-box; background-color: var(--light); font-family: var(--bodyFont); color: var(--darkgray); } .text-highlight { background-color: var(--textHighlight); padding: 0 0.1rem; border-radius: 5px; } ::selection { background: color-mix(in srgb, var(--tertiary) 60%, rgba(255, 255, 255, 0)); color: var(--darkgray); } p, ul, text, a, tr, td, li, ol, ul, .katex, .math, .typst-doc, g[class~="typst-text"] { color: var(--darkgray); fill: var(--darkgray); overflow-wrap: break-word; text-wrap: pretty; } path[class~="typst-shape"] { stroke: var(--darkgray); } .math { &.math-display { text-align: center; } } article { > mjx-container.MathJax, blockquote > div > mjx-container.MathJax { display: flex; > svg { margin-left: auto; margin-right: auto; } } blockquote > div > mjx-container.MathJax > svg { margin-top: 1rem; margin-bottom: 1rem; } } strong { font-weight: $semiBoldWeight; } a { font-weight: $semiBoldWeight; text-decoration: none; transition: color 0.2s ease; color: var(--secondary); &:hover { color: var(--tertiary); } &.internal { text-decoration: none; background-color: var(--highlight); padding: 0 0.1rem; border-radius: 5px; line-height: 1.4rem; &.broken { color: var(--secondary); opacity: 0.5; transition: opacity 0.2s ease; &:hover { opacity: 0.8; } } &:has(> img) { background-color: transparent; border-radius: 0; padding: 0; } &.tag-link { &::before { content: "#"; } } } &.external .external-icon { height: 1ex; margin: 0 0.15em; > path { fill: var(--dark); } } } .flex-component { display: flex; } .desktop-only { display: initial; &.flex-component { display: flex; } @media all and ($mobile) { &.flex-component { display: none; } display: none; } } .mobile-only { display: none; &.flex-component { display: none; } @media all and ($mobile) { &.flex-component { display: flex; } display: initial; } } .page { max-width: calc(#{map.get($breakpoints, desktop)} + 300px); margin: 0 auto; & article { & > h1 { font-size: 2rem; } & li:has(> input[type="checkbox"]) { list-style-type: none; padding-left: 0; } & li:has(> input[type="checkbox"]:checked) { text-decoration: line-through; text-decoration-color: var(--gray); color: var(--gray); } & li > * { margin-top: 0; margin-bottom: 0; } p > strong { color: var(--dark); } } & > #quartz-body { display: grid; grid-template-columns: #{map.get($desktopGrid, templateColumns)}; grid-template-rows: #{map.get($desktopGrid, templateRows)}; column-gap: #{map.get($desktopGrid, columnGap)}; row-gap: #{map.get($desktopGrid, rowGap)}; grid-template-areas: #{map.get($desktopGrid, templateAreas)}; @media all and ($tablet) { grid-template-columns: #{map.get($tabletGrid, templateColumns)}; grid-template-rows: #{map.get($tabletGrid, templateRows)}; column-gap: #{map.get($tabletGrid, columnGap)}; row-gap: #{map.get($tabletGrid, rowGap)}; grid-template-areas: #{map.get($tabletGrid, templateAreas)}; } @media all and ($mobile) { grid-template-columns: #{map.get($mobileGrid, templateColumns)}; grid-template-rows: #{map.get($mobileGrid, templateRows)}; column-gap: #{map.get($mobileGrid, columnGap)}; row-gap: #{map.get($mobileGrid, rowGap)}; grid-template-areas: #{map.get($mobileGrid, templateAreas)}; } @media all and not ($desktop) { padding: 0 1rem; } @media all and ($mobile) { margin: 0 auto; } & .sidebar { gap: 1.2rem; top: 0; box-sizing: border-box; padding: $topSpacing 2rem 2rem 2rem; display: flex; height: 100vh; position: sticky; } & .sidebar.left { z-index: 1; grid-area: grid-sidebar-left; flex-direction: column; @media all and ($mobile) { gap: 0; align-items: center; position: initial; display: flex; height: unset; flex-direction: row; padding: 0; padding-top: 2rem; } } & .sidebar.right { grid-area: grid-sidebar-right; margin-right: 0; flex-direction: column; @media all and ($mobile) { margin-left: inherit; margin-right: inherit; } @media all and not ($desktop) { position: initial; height: unset; width: 100%; flex-direction: row; padding: 0; & > * { flex: 1; max-height: 24rem; } & > .toc { display: none; } } } & .page-header, & .page-footer { margin-top: 1rem; } & .page-header { grid-area: grid-header; margin: $topSpacing 0 0 0; @media all and ($mobile) { margin-top: 0; padding: 0; } } & .center > article { grid-area: grid-center; } & footer { grid-area: grid-footer; } & .center, & footer { max-width: 100%; min-width: 100%; margin-left: auto; margin-right: auto; @media all and ($tablet) { margin-right: 0; } @media all and ($mobile) { margin-right: 0; margin-left: 0; } } & footer { margin-left: 0; } } } .footnotes { margin-top: 2rem; border-top: 1px solid var(--lightgray); } input[type="checkbox"] { transform: translateY(2px); color: var(--secondary); border: 1px solid var(--lightgray); border-radius: 3px; background-color: var(--light); position: relative; margin-inline-end: 0.2rem; margin-inline-start: -1.4rem; appearance: none; width: 16px; height: 16px; &:checked { border-color: var(--secondary); background-color: var(--secondary); &::after { content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; display: block; border: solid var(--light); border-width: 0 2px 2px 0; transform: rotate(45deg); } } } blockquote { margin: 1rem 0; border-left: 3px solid var(--secondary); padding-left: 1rem; transition: border-color 0.2s ease; } h1, h2, h3, h4, h5, h6, thead { font-family: var(--headerFont); color: var(--dark); font-weight: revert; margin-bottom: 0; article > & > a[role="anchor"] { color: var(--dark); background-color: transparent; } } h1, h2, h3, h4, h5, h6 { &[id] > a[href^="#"] { margin: 0 0.5rem; opacity: 0; transition: opacity 0.2s ease; transform: translateY(-0.1rem); font-family: var(--codeFont); user-select: none; } &[id]:hover > a { opacity: 1; } &:not([id]) > a[role="anchor"] { display: none; } } // typography improvements h1 { font-size: 1.75rem; margin-top: 2.25rem; margin-bottom: 1rem; } h2 { font-size: 1.4rem; margin-top: 1.9rem; margin-bottom: 1rem; } h3 { font-size: 1.12rem; margin-top: 1.62rem; margin-bottom: 1rem; } h4, h5, h6 { font-size: 1rem; margin-top: 1.5rem; margin-bottom: 1rem; } figure[data-rehype-pretty-code-figure] { margin: 0; position: relative; line-height: 1.6rem; position: relative; & > [data-rehype-pretty-code-title] { font-family: var(--codeFont); font-size: 0.9rem; padding: 0.1rem 0.5rem; border: 1px solid var(--lightgray); width: fit-content; border-radius: 5px; margin-bottom: -0.5rem; color: var(--darkgray); } & > pre { padding: 0; } } pre { font-family: var(--codeFont); padding: 0 0.5rem; border-radius: 5px; overflow-x: auto; border: 1px solid var(--lightgray); position: relative; &:has(> code.mermaid) { border: none; } & > code { background: none; padding: 0; font-size: 0.85rem; counter-reset: line; counter-increment: line 0; display: grid; padding: 0.5rem 0; overflow-x: auto; & [data-highlighted-chars] { background-color: var(--highlight); border-radius: 5px; } & > [data-line] { padding: 0 0.25rem; box-sizing: border-box; border-left: 3px solid transparent; &[data-highlighted-line] { background-color: var(--highlight); border-left: 3px solid var(--secondary); } &::before { content: counter(line); counter-increment: line; width: 1rem; margin-right: 1rem; display: inline-block; text-align: right; color: rgba(115, 138, 148, 0.6); } } &[data-line-numbers-max-digits="2"] > [data-line]::before { width: 2rem; } &[data-line-numbers-max-digits="3"] > [data-line]::before { width: 3rem; } } } code { font-size: 0.9em; color: var(--dark); font-family: var(--codeFont); border-radius: 5px; padding: 0.1rem 0.2rem; background: var(--lightgray); } tbody, li, p { line-height: 1.6rem; } .table-container { overflow-x: auto; & > table { margin: 1rem; padding: 1.5rem; border-collapse: collapse; th, td { min-width: 75px; } & > * { line-height: 2rem; } } } th { text-align: left; padding: 0.4rem 0.7rem; border-bottom: 2px solid var(--gray); } td { padding: 0.2rem 0.7rem; } tr { border-bottom: 1px solid var(--lightgray); &:last-child { border-bottom: none; } } img { max-width: 100%; border-radius: 5px; margin: 1rem 0; content-visibility: auto; } p > img + em { display: block; transform: translateY(-1rem); } hr { width: 100%; margin: 2rem auto; height: 1px; border: none; background-color: var(--lightgray); } audio, video { width: 100%; border-radius: 5px; } .spacer { flex: 2 1 auto; } div:has(> .overflow) { max-height: 100%; overflow-y: hidden; } ul.overflow, ol.overflow { max-height: 100%; overflow-y: auto; width: 100%; margin-bottom: 0; // clearfix content: ""; clear: both; & > li.overflow-end { height: 0.5rem; margin: 0; } &.gradient-active { mask-image: linear-gradient(to bottom, black calc(100% - 50px), transparent 100%); } } .transclude { ul { padding-left: 1rem; } } .katex-display { display: initial; overflow-x: auto; overflow-y: hidden; } .external-embed.youtube, iframe.pdf { aspect-ratio: 16 / 9; height: 100%; width: 100%; border-radius: 5px; } .navigation-progress { position: fixed; top: 0; left: 0; width: 0; height: 3px; background: var(--secondary); transition: width 0.2s ease; z-index: 9999; } ================================================ FILE: quartz/styles/callouts.scss ================================================ @use "./variables.scss" as *; @use "sass:color"; .callout { border: 1px solid var(--border); background-color: var(--bg); border-radius: 5px; padding: 0 1rem; overflow-y: hidden; box-sizing: border-box; & > .callout-content { display: grid; transition: grid-template-rows 0.1s cubic-bezier(0.02, 0.01, 0.47, 1); overflow: hidden; & > :first-child { margin-top: 0; } } --callout-icon-note: url('data:image/svg+xml; utf8, '); --callout-icon-abstract: url('data:image/svg+xml; utf8, '); --callout-icon-info: url('data:image/svg+xml; utf8, '); --callout-icon-todo: url('data:image/svg+xml; utf8, '); --callout-icon-tip: url('data:image/svg+xml; utf8, '); --callout-icon-success: url('data:image/svg+xml; utf8, '); --callout-icon-question: url('data:image/svg+xml; utf8, '); --callout-icon-warning: url('data:image/svg+xml; utf8, '); --callout-icon-failure: url('data:image/svg+xml; utf8, '); --callout-icon-danger: url('data:image/svg+xml; utf8, '); --callout-icon-bug: url('data:image/svg+xml; utf8, '); --callout-icon-example: url('data:image/svg+xml; utf8, '); --callout-icon-quote: url('data:image/svg+xml; utf8, '); --callout-icon-fold: url('data:image/svg+xml,%3Csvg 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"%3E%3Cpolyline points="6 9 12 15 18 9"%3E%3C/polyline%3E%3C/svg%3E'); &[data-callout] { --color: #448aff; --border: #448aff44; --bg: #448aff10; --callout-icon: var(--callout-icon-note); } &[data-callout="abstract"] { --color: #00b0ff; --border: #00b0ff44; --bg: #00b0ff10; --callout-icon: var(--callout-icon-abstract); } &[data-callout="info"], &[data-callout="todo"] { --color: #00b8d4; --border: #00b8d444; --bg: #00b8d410; --callout-icon: var(--callout-icon-info); } &[data-callout="todo"] { --callout-icon: var(--callout-icon-todo); } &[data-callout="tip"] { --color: #00bfa5; --border: #00bfa544; --bg: #00bfa510; --callout-icon: var(--callout-icon-tip); } &[data-callout="success"] { --color: #09ad7a; --border: #09ad7144; --bg: #09ad7110; --callout-icon: var(--callout-icon-success); } &[data-callout="question"] { --color: #dba642; --border: #dba64244; --bg: #dba64210; --callout-icon: var(--callout-icon-question); } &[data-callout="warning"] { --color: #db8942; --border: #db894244; --bg: #db894210; --callout-icon: var(--callout-icon-warning); } &[data-callout="failure"], &[data-callout="danger"], &[data-callout="bug"] { --color: #db4242; --border: #db424244; --bg: #db424210; --callout-icon: var(--callout-icon-failure); } &[data-callout="bug"] { --callout-icon: var(--callout-icon-bug); } &[data-callout="danger"] { --callout-icon: var(--callout-icon-danger); } &[data-callout="example"] { --color: #7a43b5; --border: #7a43b544; --bg: #7a43b510; --callout-icon: var(--callout-icon-example); } &[data-callout="quote"] { --color: var(--secondary); --border: var(--lightgray); --callout-icon: var(--callout-icon-quote); } &.is-collapsed { & > .callout-title > .fold-callout-icon { transform: rotateZ(-90deg); } .callout-content { & > * { transition: height 0.1s cubic-bezier(0.02, 0.01, 0.47, 1), margin 0.1s cubic-bezier(0.02, 0.01, 0.47, 1), padding 0.1s cubic-bezier(0.02, 0.01, 0.47, 1); overflow-y: clip; height: 0; margin-bottom: 0; margin-top: 0; padding-bottom: 0; padding-top: 0; } & > :first-child { margin-top: -1rem; } } } } .callout-title { display: flex; align-items: flex-start; gap: 5px; padding: 1rem 0; color: var(--color); --icon-size: 18px; & .fold-callout-icon { transition: transform 0.15s ease; opacity: 0.8; cursor: pointer; --callout-icon: var(--callout-icon-fold); } & > .callout-title-inner > p { color: var(--color); margin: 0; } .callout-icon, & .fold-callout-icon { width: var(--icon-size); height: var(--icon-size); flex: 0 0 var(--icon-size); // icon support background-size: var(--icon-size) var(--icon-size); background-position: center; background-color: var(--color); mask-image: var(--callout-icon); mask-size: var(--icon-size) var(--icon-size); mask-position: center; mask-repeat: no-repeat; padding: 0.2rem 0; } .callout-title-inner { font-weight: $semiBoldWeight; } } ================================================ FILE: quartz/styles/custom.scss ================================================ @use "./base.scss"; // put your custom CSS here! ================================================ FILE: quartz/styles/syntax.scss ================================================ code[data-theme*=" "] { color: var(--shiki-light); background-color: var(--shiki-light-bg); } code[data-theme*=" "] span { color: var(--shiki-light); } [saved-theme="dark"] code[data-theme*=" "] { color: var(--shiki-dark); background-color: var(--shiki-dark-bg); } [saved-theme="dark"] code[data-theme*=" "] span { color: var(--shiki-dark); } ================================================ FILE: quartz/styles/variables.scss ================================================ @use "sass:map"; /** * Layout breakpoints * $mobile: screen width below this value will use mobile styles * $desktop: screen width above this value will use desktop styles * Screen width between $mobile and $desktop width will use the tablet layout. * assuming mobile < desktop */ $breakpoints: ( mobile: 800px, desktop: 1200px, ); $mobile: "(max-width: #{map.get($breakpoints, mobile)})"; $tablet: "(min-width: #{map.get($breakpoints, mobile)}) and (max-width: #{map.get($breakpoints, desktop)})"; $desktop: "(min-width: #{map.get($breakpoints, desktop)})"; $pageWidth: #{map.get($breakpoints, mobile)}; $sidePanelWidth: 320px; //380px; $topSpacing: 6rem; $boldWeight: 700; $semiBoldWeight: 600; $normalWeight: 400; $mobileGrid: ( templateRows: "auto auto auto auto auto", templateColumns: "auto", rowGap: "5px", columnGap: "5px", templateAreas: '"grid-sidebar-left"\ "grid-header"\ "grid-center"\ "grid-sidebar-right"\ "grid-footer"', ); $tabletGrid: ( templateRows: "auto auto auto auto", templateColumns: "#{$sidePanelWidth} auto", rowGap: "5px", columnGap: "5px", templateAreas: '"grid-sidebar-left grid-header"\ "grid-sidebar-left grid-center"\ "grid-sidebar-left grid-sidebar-right"\ "grid-sidebar-left grid-footer"', ); $desktopGrid: ( templateRows: "auto auto auto", templateColumns: "#{$sidePanelWidth} auto #{$sidePanelWidth}", rowGap: "5px", columnGap: "5px", templateAreas: '"grid-sidebar-left grid-header grid-sidebar-right"\ "grid-sidebar-left grid-center grid-sidebar-right"\ "grid-sidebar-left grid-footer grid-sidebar-right"', ); ================================================ FILE: quartz/util/clone.ts ================================================ import rfdc from "rfdc" export const clone = rfdc() ================================================ FILE: quartz/util/ctx.ts ================================================ import { QuartzConfig } from "../cfg" import { QuartzPluginData } from "../plugins/vfile" import { FileTrieNode } from "./fileTrie" import { FilePath, FullSlug } from "./path" export interface Argv { directory: string verbose: boolean output: string serve: boolean watch: boolean port: number wsPort: number remoteDevHost?: string concurrency?: number } export type BuildTimeTrieData = QuartzPluginData & { slug: string title: string filePath: string } export interface BuildCtx { buildId: string argv: Argv cfg: QuartzConfig allSlugs: FullSlug[] allFiles: FilePath[] trie?: FileTrieNode incremental: boolean } export function trieFromAllFiles(allFiles: QuartzPluginData[]): FileTrieNode { const trie = new FileTrieNode([]) allFiles.forEach((file) => { if (file.frontmatter) { trie.add({ ...file, slug: file.slug!, title: file.frontmatter.title, filePath: file.filePath!, }) } }) return trie } export type WorkerSerializableBuildCtx = Omit ================================================ FILE: quartz/util/emoji.ts ================================================ const U200D = String.fromCharCode(8205) const UFE0Fg = /\uFE0F/g export function getIconCode(char: string) { return toCodePoint(char.indexOf(U200D) < 0 ? char.replace(UFE0Fg, "") : char) } function toCodePoint(unicodeSurrogates: string) { const r = [] let c = 0, p = 0, i = 0 while (i < unicodeSurrogates.length) { c = unicodeSurrogates.charCodeAt(i++) if (p) { r.push((65536 + ((p - 55296) << 10) + (c - 56320)).toString(16)) p = 0 } else if (55296 <= c && c <= 56319) { p = c } else { r.push(c.toString(16)) } } return r.join("-") } type EmojiMap = { codePointToName: Record nameToBase64: Record } let emojimap: EmojiMap | undefined = undefined export async function loadEmoji(code: string) { if (!emojimap) { const data = await import("./emojimap.json") emojimap = data } const name = emojimap.codePointToName[`${code.toUpperCase()}`] if (!name) throw new Error(`codepoint ${code} not found in map`) const b64 = emojimap.nameToBase64[name] if (!b64) throw new Error(`name ${name} not found in map`) return b64 } ================================================ FILE: quartz/util/emojimap.json ================================================ [File too large to display: 14.6 MB] ================================================ FILE: quartz/util/escape.ts ================================================ export const escapeHTML = (unsafe: string) => { return unsafe .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """) .replaceAll("'", "'") } export const unescapeHTML = (html: string) => { return html .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll(""", '"') .replaceAll("'", "'") } ================================================ FILE: quartz/util/fileTrie.test.ts ================================================ import test, { describe, beforeEach } from "node:test" import assert from "node:assert" import { FileTrieNode } from "./fileTrie" import { FullSlug } from "./path" interface TestData { title: string slug: string filePath: string } describe("FileTrie", () => { let trie: FileTrieNode beforeEach(() => { trie = new FileTrieNode([]) }) describe("constructor", () => { test("should create an empty trie", () => { assert.deepStrictEqual(trie.children, []) assert.strictEqual(trie.slug, "") assert.strictEqual(trie.displayName, "") assert.strictEqual(trie.data, null) }) test("should set displayName from data title", () => { const data = { title: "Test Title", slug: "test", filePath: "test.md", } trie.add(data) assert.strictEqual(trie.children[0].displayName, "Test Title") }) test("should be able to set displayName", () => { const data = { title: "Test Title", slug: "test", filePath: "test.md", } trie.add(data) trie.children[0].displayName = "Modified" assert.strictEqual(trie.children[0].displayName, "Modified") }) }) describe("add", () => { test("should add a file at root level", () => { const data = { title: "Test", slug: "test", filePath: "test.md", } trie.add(data) assert.strictEqual(trie.children.length, 1) assert.strictEqual(trie.children[0].slug, "test") assert.strictEqual(trie.children[0].data, data) }) test("should handle index files", () => { const data = { title: "Index", slug: "index", filePath: "index.md", } trie.add(data) assert.strictEqual(trie.data, data) assert.strictEqual(trie.children.length, 0) }) test("should add nested files", () => { const data1 = { title: "Nested", slug: "folder/test", filePath: "folder/test.md", } const data2 = { title: "Really nested index", slug: "a/b/c/index", filePath: "a/b/c/index.md", } trie.add(data1) trie.add(data2) assert.strictEqual(trie.children.length, 2) assert.strictEqual(trie.children[0].slug, "folder/index") assert.strictEqual(trie.children[0].children.length, 1) assert.strictEqual(trie.children[0].children[0].slug, "folder/test") assert.strictEqual(trie.children[0].children[0].data, data1) assert.strictEqual(trie.children[1].slug, "a/index") assert.strictEqual(trie.children[1].children.length, 1) assert.strictEqual(trie.children[1].data, null) assert.strictEqual(trie.children[1].children[0].slug, "a/b/index") assert.strictEqual(trie.children[1].children[0].children.length, 1) assert.strictEqual(trie.children[1].children[0].data, null) assert.strictEqual(trie.children[1].children[0].children[0].slug, "a/b/c/index") assert.strictEqual(trie.children[1].children[0].children[0].data, data2) assert.strictEqual(trie.children[1].children[0].children[0].children.length, 0) }) }) describe("filter", () => { test("should filter nodes based on condition", () => { const data1 = { title: "Test1", slug: "test1", filePath: "test1.md" } const data2 = { title: "Test2", slug: "test2", filePath: "test2.md" } trie.add(data1) trie.add(data2) trie.filter((node) => node.slug !== "test1") assert.strictEqual(trie.children.length, 1) assert.strictEqual(trie.children[0].slug, "test2") }) }) describe("map", () => { test("should apply function to all nodes", () => { const data1 = { title: "Test1", slug: "test1", filePath: "test1.md" } const data2 = { title: "Test2", slug: "test2", filePath: "test2.md" } trie.add(data1) trie.add(data2) trie.map((node) => { if (node.data) { node.data.title = "Modified" } }) assert.strictEqual(trie.children[0].displayName, "Modified") assert.strictEqual(trie.children[1].displayName, "Modified") }) test("map over folders should work", () => { const data1 = { title: "Test1", slug: "test1", filePath: "test1.md" } const data2 = { title: "Test2", slug: "a/b-with-space/test2", filePath: "a/b with space/test2.md", } trie.add(data1) trie.add(data2) trie.map((node) => { if (node.isFolder) { node.displayName = `Folder: ${node.displayName}` } else { node.displayName = `File: ${node.displayName}` } }) assert.strictEqual(trie.children[0].displayName, "File: Test1") assert.strictEqual(trie.children[1].displayName, "Folder: a") assert.strictEqual(trie.children[1].children[0].displayName, "Folder: b with space") assert.strictEqual(trie.children[1].children[0].children[0].displayName, "File: Test2") }) }) describe("entries", () => { test("should return all entries", () => { const data1 = { title: "Test1", slug: "test1", filePath: "test1.md" } const data2 = { title: "Test2", slug: "a/b-with-space/test2", filePath: "a/b with space/test2.md", } trie.add(data1) trie.add(data2) const entries = trie.entries() assert.deepStrictEqual( entries.map(([path, node]) => [path, node.data]), [ ["index", trie.data], ["test1", data1], ["a/index", null], ["a/b-with-space/index", null], ["a/b-with-space/test2", data2], ], ) }) }) describe("fromEntries", () => { test("nested", () => { const trie = FileTrieNode.fromEntries([ ["index" as FullSlug, { title: "Root", slug: "index", filePath: "index.md" }], [ "folder/file1" as FullSlug, { title: "File 1", slug: "folder/file1", filePath: "folder/file1.md" }, ], [ "folder/index" as FullSlug, { title: "Folder Index", slug: "folder/index", filePath: "folder/index.md" }, ], [ "folder/file2" as FullSlug, { title: "File 2", slug: "folder/file2", filePath: "folder/file2.md" }, ], [ "folder/folder2/index" as FullSlug, { title: "Subfolder Index", slug: "folder/folder2/index", filePath: "folder/folder2/index.md", }, ], ]) assert.strictEqual(trie.children.length, 1) assert.strictEqual(trie.children[0].slug, "folder/index") assert.strictEqual(trie.children[0].children.length, 3) assert.strictEqual(trie.children[0].children[0].slug, "folder/file1") assert.strictEqual(trie.children[0].children[1].slug, "folder/file2") assert.strictEqual(trie.children[0].children[2].slug, "folder/folder2/index") assert.strictEqual(trie.children[0].children[2].children.length, 0) }) }) describe("findNode", () => { test("should find root node with empty path", () => { const data = { title: "Root", slug: "index", filePath: "index.md" } trie.add(data) const found = trie.findNode([]) assert.strictEqual(found, trie) }) test("should find node at first level", () => { const data = { title: "Test", slug: "test", filePath: "test.md" } trie.add(data) const found = trie.findNode(["test"]) assert.strictEqual(found?.data, data) }) test("should find nested node", () => { const data = { title: "Nested", slug: "folder/subfolder/test", filePath: "folder/subfolder/test.md", } trie.add(data) const found = trie.findNode(["folder", "subfolder", "test"]) assert.strictEqual(found?.data, data) // should find the folder and subfolder indexes too assert.strictEqual( trie.findNode(["folder", "subfolder", "index"]), trie.children[0].children[0], ) assert.strictEqual(trie.findNode(["folder", "index"]), trie.children[0]) }) test("should return undefined for non-existent path", () => { const data = { title: "Test", slug: "test", filePath: "test.md" } trie.add(data) const found = trie.findNode(["nonexistent"]) assert.strictEqual(found, undefined) }) test("should return undefined for partial path", () => { const data = { title: "Nested", slug: "folder/subfolder/test", filePath: "folder/subfolder/test.md", } trie.add(data) const found = trie.findNode(["folder"]) assert.strictEqual(found?.data, null) }) }) describe("getFolderPaths", () => { test("should return all folder paths", () => { const data1 = { title: "Root", slug: "index", filePath: "index.md", } const data2 = { title: "Test", slug: "folder/subfolder/test", filePath: "folder/subfolder/test.md", } const data3 = { title: "Folder Index", slug: "abc/index", filePath: "abc/index.md", } trie.add(data1) trie.add(data2) trie.add(data3) const paths = trie.getFolderPaths() assert.deepStrictEqual(paths, [ "index", "folder/index", "folder/subfolder/index", "abc/index", ]) }) }) describe("sort", () => { test("should sort nodes according to sort function", () => { const data1 = { title: "A", slug: "a", filePath: "a.md" } const data2 = { title: "B", slug: "b", filePath: "b.md" } const data3 = { title: "C", slug: "c", filePath: "c.md" } trie.add(data3) trie.add(data1) trie.add(data2) trie.sort((a, b) => a.slug.localeCompare(b.slug)) assert.deepStrictEqual( trie.children.map((n) => n.slug), ["a", "b", "c"], ) }) }) describe("pathToNode", () => { test("should return root node for empty path", () => { const data = { title: "Root", slug: "index", filePath: "index.md" } trie.add(data) const path = trie.ancestryChain([]) assert.deepStrictEqual(path, [trie]) }) test("should return root node for index path", () => { const data = { title: "Root", slug: "index", filePath: "index.md" } trie.add(data) const path = trie.ancestryChain(["index"]) assert.deepStrictEqual(path, [trie]) }) test("should return path to first level node", () => { const data = { title: "Test", slug: "test", filePath: "test.md" } trie.add(data) const path = trie.ancestryChain(["test"]) assert.deepStrictEqual(path, [trie, trie.children[0]]) }) test("should return path to nested node", () => { const data = { title: "Nested", slug: "folder/subfolder/test", filePath: "folder/subfolder/test.md", } trie.add(data) const path = trie.ancestryChain(["folder", "subfolder", "test"]) assert.deepStrictEqual(path, [ trie, trie.children[0], trie.children[0].children[0], trie.children[0].children[0].children[0], ]) }) test("should return undefined for non-existent path", () => { const data = { title: "Test", slug: "test", filePath: "test.md" } trie.add(data) const path = trie.ancestryChain(["nonexistent"]) assert.strictEqual(path, undefined) }) test("should return file data for intermediate folders", () => { const data1 = { title: "Root", slug: "index", filePath: "index.md", } const data2 = { title: "Test", slug: "folder/subfolder/test", filePath: "folder/subfolder/test.md", } const data3 = { title: "Folder Index", slug: "folder/index", filePath: "folder/index.md", } trie.add(data1) trie.add(data2) trie.add(data3) const path = trie.ancestryChain(["folder", "subfolder"]) assert.deepStrictEqual(path, [trie, trie.children[0], trie.children[0].children[0]]) assert.strictEqual(path[1].data, data3) }) test("should return path for partial path", () => { const data = { title: "Nested", slug: "folder/subfolder/test", filePath: "folder/subfolder/test.md", } trie.add(data) const path = trie.ancestryChain(["folder"]) assert.deepStrictEqual(path, [trie, trie.children[0]]) }) }) }) ================================================ FILE: quartz/util/fileTrie.ts ================================================ import { ContentDetails } from "../plugins/emitters/contentIndex" import { FullSlug, joinSegments } from "./path" interface FileTrieData { slug: string title: string filePath: string } export class FileTrieNode { isFolder: boolean children: Array> private slugSegments: string[] // prefer showing the file path segment over the slug segment // so that folders that dont have index files can be shown as is // without dashes in the slug private fileSegmentHint?: string private displayNameOverride?: string data: T | null constructor(segments: string[], data?: T) { this.children = [] this.slugSegments = segments this.data = data ?? null this.isFolder = false this.displayNameOverride = undefined } get displayName(): string { const nonIndexTitle = this.data?.title === "index" ? undefined : this.data?.title return ( this.displayNameOverride ?? nonIndexTitle ?? this.fileSegmentHint ?? this.slugSegment ?? "" ) } set displayName(name: string) { this.displayNameOverride = name } get slug(): FullSlug { const path = joinSegments(...this.slugSegments) as FullSlug if (this.isFolder) { return joinSegments(path, "index") as FullSlug } return path } get slugSegment(): string { return this.slugSegments[this.slugSegments.length - 1] } private makeChild(path: string[], file?: T) { const fullPath = [...this.slugSegments, path[0]] const child = new FileTrieNode(fullPath, file) this.children.push(child) return child } private insert(path: string[], file: T) { if (path.length === 0) { throw new Error("path is empty") } // if we are inserting, we are a folder this.isFolder = true const segment = path[0] if (path.length === 1) { // base case, we are at the end of the path if (segment === "index") { this.data ??= file } else { this.makeChild(path, file) } } else if (path.length > 1) { // recursive case, we are not at the end of the path const child = this.children.find((c) => c.slugSegment === segment) ?? this.makeChild(path, undefined) const fileParts = file.filePath.split("/") child.fileSegmentHint = fileParts.at(-path.length) child.insert(path.slice(1), file) } } // Add new file to trie add(file: T) { this.insert(file.slug.split("/"), file) } findNode(path: string[]): FileTrieNode | undefined { if (path.length === 0 || (path.length === 1 && path[0] === "index")) { return this } return this.children.find((c) => c.slugSegment === path[0])?.findNode(path.slice(1)) } ancestryChain(path: string[]): Array> | undefined { if (path.length === 0 || (path.length === 1 && path[0] === "index")) { return [this] } const child = this.children.find((c) => c.slugSegment === path[0]) if (!child) { return undefined } const childPath = child.ancestryChain(path.slice(1)) if (!childPath) { return undefined } return [this, ...childPath] } /** * Filter trie nodes. Behaves similar to `Array.prototype.filter()`, but modifies tree in place */ filter(filterFn: (node: FileTrieNode) => boolean) { this.children = this.children.filter(filterFn) this.children.forEach((child) => child.filter(filterFn)) } /** * Map over trie nodes. Behaves similar to `Array.prototype.map()`, but modifies tree in place */ map(mapFn: (node: FileTrieNode) => void) { mapFn(this) this.children.forEach((child) => child.map(mapFn)) } /** * Sort trie nodes according to sort/compare function */ sort(sortFn: (a: FileTrieNode, b: FileTrieNode) => number) { this.children = this.children.sort(sortFn) this.children.forEach((e) => e.sort(sortFn)) } static fromEntries(entries: [FullSlug, T][]) { const trie = new FileTrieNode([]) entries.forEach(([, entry]) => trie.add(entry)) return trie } /** * Get all entries in the trie * in the a flat array including the full path and the node */ entries(): [FullSlug, FileTrieNode][] { const traverse = (node: FileTrieNode): [FullSlug, FileTrieNode][] => { const result: [FullSlug, FileTrieNode][] = [[node.slug, node]] return result.concat(...node.children.map(traverse)) } return traverse(this) } /** * Get all folder paths in the trie * @returns array containing folder state for trie */ getFolderPaths() { return this.entries() .filter(([_, node]) => node.isFolder) .map(([path, _]) => path) } } ================================================ FILE: quartz/util/glob.ts ================================================ import path from "path" import { FilePath } from "./path" import { globby } from "globby" export function toPosixPath(fp: string): string { return fp.split(path.sep).join("/") } export async function glob( pattern: string, cwd: string, ignorePatterns: string[], ): Promise { const fps = ( await globby(pattern, { cwd, ignore: ignorePatterns, gitignore: true, }) ).map(toPosixPath) return fps as FilePath[] } ================================================ FILE: quartz/util/jsx.tsx ================================================ import { Components, Jsx, toJsxRuntime } from "hast-util-to-jsx-runtime" import { Node, Root } from "hast" import { Fragment, jsx, jsxs } from "preact/jsx-runtime" import { trace } from "./trace" import { type FilePath } from "./path" const customComponents: Components = { table: (props) => (
      ), } export function htmlToJsx(fp: FilePath, tree: Node) { try { return toJsxRuntime(tree as Root, { Fragment, jsx: jsx as Jsx, jsxs: jsxs as Jsx, elementAttributeNameCase: "html", components: customComponents, }) } catch (e) { trace(`Failed to parse Markdown in \`${fp}\` into JSX`, e as Error) } } ================================================ FILE: quartz/util/lang.ts ================================================ export function capitalize(s: string): string { return s.substring(0, 1).toUpperCase() + s.substring(1) } export function classNames( displayClass?: "mobile-only" | "desktop-only", ...classes: string[] ): string { if (displayClass) { classes.push(displayClass) } return classes.join(" ") } ================================================ FILE: quartz/util/log.ts ================================================ import truncate from "ansi-truncate" import readline from "readline" export class QuartzLogger { verbose: boolean private spinnerInterval: NodeJS.Timeout | undefined private spinnerText: string = "" private updateSuffix: string = "" private spinnerIndex: number = 0 private readonly spinnerChars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] constructor(verbose: boolean) { const isInteractiveTerminal = process.stdout.isTTY && process.env.TERM !== "dumb" && !process.env.CI this.verbose = verbose || !isInteractiveTerminal } start(text: string) { this.spinnerText = text if (this.verbose) { console.log(text) } else { this.spinnerIndex = 0 this.spinnerInterval = setInterval(() => { readline.clearLine(process.stdout, 0) readline.cursorTo(process.stdout, 0) const columns = process.stdout.columns || 80 let output = `${this.spinnerChars[this.spinnerIndex]} ${this.spinnerText}` if (this.updateSuffix) { output += `: ${this.updateSuffix}` } const truncated = truncate(output, columns) process.stdout.write(truncated) this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerChars.length }, 50) } } updateText(text: string) { this.updateSuffix = text } end(text?: string) { if (!this.verbose && this.spinnerInterval) { clearInterval(this.spinnerInterval) this.spinnerInterval = undefined readline.clearLine(process.stdout, 0) readline.cursorTo(process.stdout, 0) } if (text) { console.log(text) } } } ================================================ FILE: quartz/util/og.tsx ================================================ import { promises as fs } from "fs" import { FontWeight, SatoriOptions } from "satori/wasm" import { GlobalConfiguration } from "../cfg" import { QuartzPluginData } from "../plugins/vfile" import { JSXInternal } from "preact/src/jsx" import { FontSpecification, getFontSpecificationName, ThemeKey } from "./theme" import path from "path" import { QUARTZ } from "./path" import { formatDate, getDate } from "../components/Date" import readingTime from "reading-time" import { i18n } from "../i18n" import { styleText } from "util" const defaultHeaderWeight = [700] const defaultBodyWeight = [400] export async function getSatoriFonts(headerFont: FontSpecification, bodyFont: FontSpecification) { // Get all weights for header and body fonts const headerWeights: FontWeight[] = ( typeof headerFont === "string" ? defaultHeaderWeight : (headerFont.weights ?? defaultHeaderWeight) ) as FontWeight[] const bodyWeights: FontWeight[] = ( typeof bodyFont === "string" ? defaultBodyWeight : (bodyFont.weights ?? defaultBodyWeight) ) as FontWeight[] const headerFontName = typeof headerFont === "string" ? headerFont : headerFont.name const bodyFontName = typeof bodyFont === "string" ? bodyFont : bodyFont.name // Fetch fonts for all weights and convert to satori format in one go const headerFontPromises = headerWeights.map(async (weight) => { const data = await fetchTtf(headerFontName, weight) if (!data) return null return { name: headerFontName, data, weight, style: "normal" as const, } }) const bodyFontPromises = bodyWeights.map(async (weight) => { const data = await fetchTtf(bodyFontName, weight) if (!data) return null return { name: bodyFontName, data, weight, style: "normal" as const, } }) const [headerFonts, bodyFonts] = await Promise.all([ Promise.all(headerFontPromises), Promise.all(bodyFontPromises), ]) // Filter out any failed fetches and combine header and body fonts const fonts: SatoriOptions["fonts"] = [ ...headerFonts.filter((font): font is NonNullable => font !== null), ...bodyFonts.filter((font): font is NonNullable => font !== null), ] return fonts } /** * Get the `.ttf` file of a google font * @param fontName name of google font * @param weight what font weight to fetch font * @returns `.ttf` file of google font */ export async function fetchTtf( rawFontName: string, weight: FontWeight, ): Promise | undefined> { const fontName = rawFontName.replaceAll(" ", "+") const cacheKey = `${fontName}-${weight}` const cacheDir = path.join(QUARTZ, ".quartz-cache", "fonts") const cachePath = path.join(cacheDir, cacheKey) // Check if font exists in cache try { await fs.access(cachePath) return fs.readFile(cachePath) } catch (error) { // ignore errors and fetch font } // Get css file from google fonts const cssResponse = await fetch( `https://fonts.googleapis.com/css2?family=${fontName}:wght@${weight}`, ) const css = await cssResponse.text() // Extract .ttf url from css file const urlRegex = /url\((https:\/\/fonts.gstatic.com\/s\/.*?.ttf)\)/g const match = urlRegex.exec(css) if (!match) { console.log( styleText( "yellow", `\nWarning: Failed to fetch font ${rawFontName} with weight ${weight}, got ${cssResponse.statusText}`, ), ) return } // fontData is an ArrayBuffer containing the .ttf file data const fontResponse = await fetch(match[1]) const fontData = Buffer.from(await fontResponse.arrayBuffer()) await fs.mkdir(cacheDir, { recursive: true }) await fs.writeFile(cachePath, fontData) return fontData } export type SocialImageOptions = { /** * What color scheme to use for image generation (uses colors from config theme) */ colorScheme: ThemeKey /** * Height to generate image with in pixels (should be around 630px) */ height: number /** * Width to generate image with in pixels (should be around 1200px) */ width: number /** * Whether to use the auto generated image for the root path ("/", when set to false) or the default og image (when set to true). */ excludeRoot: boolean /** * JSX to use for generating image. See satori docs for more info (https://github.com/vercel/satori) */ imageStructure: ( options: ImageOptions & { userOpts: UserOpts iconBase64?: string }, ) => JSXInternal.Element } export type UserOpts = Omit export type ImageOptions = { /** * what title to use as header in image */ title: string /** * what description to use as body in image */ description: string /** * header + body font to be used when generating satori image (as promise to work around sync in component) */ fonts: SatoriOptions["fonts"] /** * `GlobalConfiguration` of quartz (used for theme/typography) */ cfg: GlobalConfiguration /** * full file data of current page */ fileData: QuartzPluginData } // This is the default template for generated social image. export const defaultImage: SocialImageOptions["imageStructure"] = ({ cfg, userOpts, title, description, fileData, iconBase64, }) => { const { colorScheme } = userOpts const fontBreakPoint = 32 const useSmallerFont = title.length > fontBreakPoint // Format date if available const rawDate = getDate(cfg, fileData) const date = rawDate ? formatDate(rawDate, cfg.locale) : null // Calculate reading time const { minutes } = readingTime(fileData.text ?? "") const readingTimeText = i18n(cfg.locale).components.contentMeta.readingTime({ minutes: Math.ceil(minutes), }) // Get tags if available const tags = fileData.frontmatter?.tags ?? [] const bodyFont = getFontSpecificationName(cfg.theme.typography.body) const headerFont = getFontSpecificationName(cfg.theme.typography.header) return (
      {/* Header Section */}
      {iconBase64 && ( )}
      {cfg.baseUrl}
      {/* Title Section */}

      {title}

      {/* Description Section */}

      {description}

      {/* Footer with Metadata */}
      {/* Left side - Date and Reading Time */}
      {date && (
      {date}
      )}
      {readingTimeText}
      {/* Right side - Tags */}
      {tags.slice(0, 3).map((tag: string) => (
      #{tag}
      ))}
      ) } ================================================ FILE: quartz/util/path.test.ts ================================================ import test, { describe } from "node:test" import * as path from "./path" import assert from "node:assert" import { FullSlug, TransformOptions, SimpleSlug } from "./path" describe("typeguards", () => { test("isSimpleSlug", () => { assert(path.isSimpleSlug("")) assert(path.isSimpleSlug("abc")) assert(path.isSimpleSlug("abc/")) assert(path.isSimpleSlug("notindex")) assert(path.isSimpleSlug("notindex/def")) assert(!path.isSimpleSlug("//")) assert(!path.isSimpleSlug("index")) assert(!path.isSimpleSlug("https://example.com")) assert(!path.isSimpleSlug("/abc")) assert(!path.isSimpleSlug("abc/index")) assert(!path.isSimpleSlug("abc#anchor")) assert(!path.isSimpleSlug("abc?query=1")) assert(!path.isSimpleSlug("index.md")) assert(!path.isSimpleSlug("index.html")) }) test("isRelativeURL", () => { assert(path.isRelativeURL(".")) assert(path.isRelativeURL("..")) assert(path.isRelativeURL("./abc/def")) assert(path.isRelativeURL("./abc/def#an-anchor")) assert(path.isRelativeURL("./abc/def?query=1#an-anchor")) assert(path.isRelativeURL("../abc/def")) assert(path.isRelativeURL("./abc/def.pdf")) assert(!path.isRelativeURL("abc")) assert(!path.isRelativeURL("/abc/def")) assert(!path.isRelativeURL("")) assert(!path.isRelativeURL("./abc/def.html")) assert(!path.isRelativeURL("./abc/def.md")) }) test("isAbsoluteURL", () => { assert(path.isAbsoluteURL("https://example.com")) assert(path.isAbsoluteURL("http://example.com")) assert(path.isAbsoluteURL("ftp://example.com/a/b/c")) assert(path.isAbsoluteURL("http://host/%25")) assert(path.isAbsoluteURL("file://host/twoslashes?more//slashes")) assert(!path.isAbsoluteURL("example.com/abc/def")) assert(!path.isAbsoluteURL("abc")) }) test("isFullSlug", () => { assert(path.isFullSlug("index")) assert(path.isFullSlug("abc/def")) assert(path.isFullSlug("html.energy")) assert(path.isFullSlug("test.pdf")) assert(!path.isFullSlug(".")) assert(!path.isFullSlug("./abc/def")) assert(!path.isFullSlug("../abc/def")) assert(!path.isFullSlug("abc/def#anchor")) assert(!path.isFullSlug("abc/def?query=1")) assert(!path.isFullSlug("note with spaces")) }) test("isFilePath", () => { assert(path.isFilePath("content/index.md")) assert(path.isFilePath("content/test.png")) assert(!path.isFilePath("../test.pdf")) assert(!path.isFilePath("content/test")) assert(!path.isFilePath("./content/test")) }) }) describe("transforms", () => { function asserts( pairs: [string, string][], transform: (inp: Inp) => Out, checkPre: (x: any) => x is Inp, checkPost: (x: any) => x is Out, ) { for (const [inp, expected] of pairs) { assert(checkPre(inp), `${inp} wasn't the expected input type`) const actual = transform(inp) assert.strictEqual( actual, expected, `after transforming ${inp}, '${actual}' was not '${expected}'`, ) assert(checkPost(actual), `${actual} wasn't the expected output type`) } } test("simplifySlug", () => { asserts( [ ["index", "/"], ["abc", "abc"], ["abc/index", "abc/"], ["abc/def", "abc/def"], ], path.simplifySlug, path.isFullSlug, path.isSimpleSlug, ) }) test("slugifyFilePath", () => { asserts( [ ["content/index.md", "content/index"], ["content/index.html", "content/index"], ["content/_index.md", "content/index"], ["/content/index.md", "content/index"], ["content/cool.png", "content/cool.png"], ["index.md", "index"], ["test.mp4", "test.mp4"], ["note with spaces.md", "note-with-spaces"], ["notes.with.dots.md", "notes.with.dots"], ["test/special chars?.md", "test/special-chars"], ["test/special chars #3.md", "test/special-chars-3"], ["cool/what about r&d?.md", "cool/what-about-r-and-d"], ], path.slugifyFilePath, path.isFilePath, path.isFullSlug, ) }) test("transformInternalLink", () => { asserts( [ ["", "."], [".", "."], ["./", "./"], ["./index", "./"], ["./index#abc", "./#abc"], ["./index.html", "./"], ["./index.md", "./"], ["./index.css", "./index.css"], ["content", "./content"], ["content/test.md", "./content/test"], ["content/test.pdf", "./content/test.pdf"], ["./content/test.md", "./content/test"], ["../content/test.md", "../content/test"], ["tags/", "./tags/"], ["/tags/", "./tags/"], ["content/with spaces", "./content/with-spaces"], ["content/with spaces/index", "./content/with-spaces/"], ["content/with spaces#and Anchor!", "./content/with-spaces#and-anchor"], ], path.transformInternalLink, (_x: string): _x is string => true, path.isRelativeURL, ) }) test("pathToRoot", () => { asserts( [ ["index", "."], ["abc", "."], ["abc/def", ".."], ["abc/def/ghi", "../.."], ["abc/def/index", "../.."], ], path.pathToRoot, path.isFullSlug, path.isRelativeURL, ) }) test("joinSegments", () => { assert.strictEqual(path.joinSegments("a", "b"), "a/b") assert.strictEqual(path.joinSegments("a/", "b"), "a/b") assert.strictEqual(path.joinSegments("a", "b/"), "a/b/") assert.strictEqual(path.joinSegments("a/", "b/"), "a/b/") // preserve leading and trailing slashes assert.strictEqual(path.joinSegments("/a", "b"), "/a/b") assert.strictEqual(path.joinSegments("/a/", "b"), "/a/b") assert.strictEqual(path.joinSegments("/a", "b/"), "/a/b/") assert.strictEqual(path.joinSegments("/a/", "b/"), "/a/b/") // lone slash assert.strictEqual(path.joinSegments("/a/", "b", "/"), "/a/b/") assert.strictEqual(path.joinSegments("a/", "b" + "/"), "a/b/") // works with protocol specifiers assert.strictEqual(path.joinSegments("https://example.com", "a"), "https://example.com/a") assert.strictEqual(path.joinSegments("https://example.com/", "a"), "https://example.com/a") assert.strictEqual(path.joinSegments("https://example.com", "a/"), "https://example.com/a/") assert.strictEqual(path.joinSegments("https://example.com/", "a/"), "https://example.com/a/") }) }) describe("link strategies", () => { const allSlugs = [ "a/b/c", "a/b/d", "a/b/index", "e/f", "e/g/h", "index", "a/test.png", ] as FullSlug[] describe("absolute", () => { const opts: TransformOptions = { strategy: "absolute", allSlugs, } test("from a/b/c", () => { const cur = "a/b/c" as FullSlug assert.strictEqual(path.transformLink(cur, "a/b/d", opts), "../../a/b/d") assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "../../a/b/") assert.strictEqual(path.transformLink(cur, "e/f", opts), "../../e/f") assert.strictEqual(path.transformLink(cur, "e/g/h", opts), "../../e/g/h") assert.strictEqual(path.transformLink(cur, "index", opts), "../../") assert.strictEqual(path.transformLink(cur, "index.png", opts), "../../index.png") assert.strictEqual(path.transformLink(cur, "index#abc", opts), "../../#abc") assert.strictEqual(path.transformLink(cur, "tag/test", opts), "../../tag/test") assert.strictEqual(path.transformLink(cur, "a/b/c#test", opts), "../../a/b/c#test") assert.strictEqual(path.transformLink(cur, "a/test.png", opts), "../../a/test.png") }) test("from a/b/index", () => { const cur = "a/b/index" as FullSlug assert.strictEqual(path.transformLink(cur, "a/b/d", opts), "../../a/b/d") assert.strictEqual(path.transformLink(cur, "a/b", opts), "../../a/b") assert.strictEqual(path.transformLink(cur, "index", opts), "../../") }) test("from index", () => { const cur = "index" as FullSlug assert.strictEqual(path.transformLink(cur, "index", opts), "./") assert.strictEqual(path.transformLink(cur, "a/b/c", opts), "./a/b/c") assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "./a/b/") }) }) describe("shortest", () => { const opts: TransformOptions = { strategy: "shortest", allSlugs, } test("from a/b/c", () => { const cur = "a/b/c" as FullSlug assert.strictEqual(path.transformLink(cur, "d", opts), "../../a/b/d") assert.strictEqual(path.transformLink(cur, "h", opts), "../../e/g/h") assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "../../a/b/") assert.strictEqual(path.transformLink(cur, "a/b/index.png", opts), "../../a/b/index.png") assert.strictEqual(path.transformLink(cur, "a/b/index#abc", opts), "../../a/b/#abc") assert.strictEqual(path.transformLink(cur, "index", opts), "../../") assert.strictEqual(path.transformLink(cur, "index.png", opts), "../../index.png") assert.strictEqual(path.transformLink(cur, "test.png", opts), "../../a/test.png") assert.strictEqual(path.transformLink(cur, "index#abc", opts), "../../#abc") }) test("from a/b/index", () => { const cur = "a/b/index" as FullSlug assert.strictEqual(path.transformLink(cur, "d", opts), "../../a/b/d") assert.strictEqual(path.transformLink(cur, "h", opts), "../../e/g/h") assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "../../a/b/") assert.strictEqual(path.transformLink(cur, "index", opts), "../../") }) test("from index", () => { const cur = "index" as FullSlug assert.strictEqual(path.transformLink(cur, "d", opts), "./a/b/d") assert.strictEqual(path.transformLink(cur, "h", opts), "./e/g/h") assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "./a/b/") assert.strictEqual(path.transformLink(cur, "index", opts), "./") }) }) describe("relative", () => { const opts: TransformOptions = { strategy: "relative", allSlugs, } test("from a/b/c", () => { const cur = "a/b/c" as FullSlug assert.strictEqual(path.transformLink(cur, "d", opts), "./d") assert.strictEqual(path.transformLink(cur, "index", opts), "./") assert.strictEqual(path.transformLink(cur, "../../../index", opts), "../../../") assert.strictEqual(path.transformLink(cur, "../../../index.png", opts), "../../../index.png") assert.strictEqual(path.transformLink(cur, "../../../index#abc", opts), "../../../#abc") assert.strictEqual(path.transformLink(cur, "../../../", opts), "../../../") assert.strictEqual( path.transformLink(cur, "../../../a/test.png", opts), "../../../a/test.png", ) assert.strictEqual(path.transformLink(cur, "../../../e/g/h", opts), "../../../e/g/h") assert.strictEqual(path.transformLink(cur, "../../../e/g/h", opts), "../../../e/g/h") assert.strictEqual(path.transformLink(cur, "../../../e/g/h#abc", opts), "../../../e/g/h#abc") }) test("from a/b/index", () => { const cur = "a/b/index" as FullSlug assert.strictEqual(path.transformLink(cur, "../../index", opts), "../../") assert.strictEqual(path.transformLink(cur, "../../", opts), "../../") assert.strictEqual(path.transformLink(cur, "../../e/g/h", opts), "../../e/g/h") assert.strictEqual(path.transformLink(cur, "c", opts), "./c") }) test("from index", () => { const cur = "index" as FullSlug assert.strictEqual(path.transformLink(cur, "e/g/h", opts), "./e/g/h") assert.strictEqual(path.transformLink(cur, "a/b/index", opts), "./a/b/") }) }) }) describe("resolveRelative", () => { test("from index", () => { assert.strictEqual(path.resolveRelative("index" as FullSlug, "index" as FullSlug), "./") assert.strictEqual(path.resolveRelative("index" as FullSlug, "abc" as FullSlug), "./abc") assert.strictEqual( path.resolveRelative("index" as FullSlug, "abc/def" as FullSlug), "./abc/def", ) assert.strictEqual( path.resolveRelative("index" as FullSlug, "abc/def/ghi" as FullSlug), "./abc/def/ghi", ) }) test("from nested page", () => { assert.strictEqual(path.resolveRelative("abc/def" as FullSlug, "index" as FullSlug), "../") assert.strictEqual(path.resolveRelative("abc/def" as FullSlug, "abc" as FullSlug), "../abc") assert.strictEqual( path.resolveRelative("abc/def" as FullSlug, "abc/def" as FullSlug), "../abc/def", ) assert.strictEqual( path.resolveRelative("abc/def" as FullSlug, "ghi/jkl" as FullSlug), "../ghi/jkl", ) }) test("with index paths", () => { assert.strictEqual(path.resolveRelative("abc/index" as FullSlug, "index" as FullSlug), "../") assert.strictEqual( path.resolveRelative("abc/def/index" as FullSlug, "index" as FullSlug), "../../", ) assert.strictEqual(path.resolveRelative("index" as FullSlug, "abc/index" as FullSlug), "./abc/") assert.strictEqual( path.resolveRelative("abc/def" as FullSlug, "abc/index" as FullSlug), "../abc/", ) }) test("with simple slugs", () => { assert.strictEqual(path.resolveRelative("abc/def" as FullSlug, "" as SimpleSlug), "../") assert.strictEqual(path.resolveRelative("abc/def" as FullSlug, "ghi" as SimpleSlug), "../ghi") assert.strictEqual(path.resolveRelative("abc/def" as FullSlug, "ghi/" as SimpleSlug), "../ghi/") }) }) ================================================ FILE: quartz/util/path.ts ================================================ import { slug as slugAnchor } from "github-slugger" import type { Element as HastElement } from "hast" import { clone } from "./clone" // this file must be isomorphic so it can't use node libs (e.g. path) export const QUARTZ = "quartz" /// Utility type to simulate nominal types in TypeScript type SlugLike = string & { __brand: T } /** Cannot be relative and must have a file extension. */ export type FilePath = SlugLike<"filepath"> export function isFilePath(s: string): s is FilePath { const validStart = !s.startsWith(".") return validStart && _hasFileExtension(s) } /** Cannot be relative and may not have leading or trailing slashes. It can have `index` as it's last segment. Use this wherever possible is it's the most 'general' interpretation of a slug. */ export type FullSlug = SlugLike<"full"> export function isFullSlug(s: string): s is FullSlug { const validStart = !(s.startsWith(".") || s.startsWith("/")) const validEnding = !s.endsWith("/") return validStart && validEnding && !containsForbiddenCharacters(s) } /** Shouldn't be a relative path and shouldn't have `/index` as an ending or a file extension. It _can_ however have a trailing slash to indicate a folder path. */ export type SimpleSlug = SlugLike<"simple"> export function isSimpleSlug(s: string): s is SimpleSlug { const validStart = !(s.startsWith(".") || (s.length > 1 && s.startsWith("/"))) const validEnding = !endsWith(s, "index") return validStart && !containsForbiddenCharacters(s) && validEnding && !_hasFileExtension(s) } /** Can be found on `href`s but can also be constructed for client-side navigation (e.g. search and graph) */ export type RelativeURL = SlugLike<"relative"> export function isRelativeURL(s: string): s is RelativeURL { const validStart = /^\.{1,2}/.test(s) const validEnding = !endsWith(s, "index") return validStart && validEnding && ![".md", ".html"].includes(getFileExtension(s) ?? "") } export function isAbsoluteURL(s: string): boolean { try { new URL(s) } catch { return false } return true } export function getFullSlug(window: Window): FullSlug { const res = window.document.body.dataset.slug! as FullSlug return res } function sluggify(s: string): string { return s .split("/") .map((segment) => segment .replace(/\s/g, "-") .replace(/&/g, "-and-") .replace(/%/g, "-percent") .replace(/\?/g, "") .replace(/#/g, ""), ) .join("/") // always use / as sep .replace(/\/$/, "") } export function slugifyFilePath(fp: FilePath, excludeExt?: boolean): FullSlug { fp = stripSlashes(fp) as FilePath let ext = getFileExtension(fp) const withoutFileExt = fp.replace(new RegExp(ext + "$"), "") if (excludeExt || [".md", ".html", undefined].includes(ext)) { ext = "" } let slug = sluggify(withoutFileExt) // treat _index as index if (endsWith(slug, "_index")) { slug = slug.replace(/_index$/, "index") } return (slug + ext) as FullSlug } export function simplifySlug(fp: FullSlug): SimpleSlug { const res = stripSlashes(trimSuffix(fp, "index"), true) return (res.length === 0 ? "/" : res) as SimpleSlug } export function transformInternalLink(link: string): RelativeURL { let [fplike, anchor] = splitAnchor(decodeURI(link)) const folderPath = isFolderPath(fplike) let segments = fplike.split("/").filter((x) => x.length > 0) let prefix = segments.filter(isRelativeSegment).join("/") let fp = segments.filter((seg) => !isRelativeSegment(seg) && seg !== "").join("/") // manually add ext here as we want to not strip 'index' if it has an extension const simpleSlug = simplifySlug(slugifyFilePath(fp as FilePath)) const joined = joinSegments(stripSlashes(prefix), stripSlashes(simpleSlug)) const trail = folderPath ? "/" : "" const res = (_addRelativeToStart(joined) + trail + anchor) as RelativeURL return res } // from micromorph/src/utils.ts // https://github.com/natemoo-re/micromorph/blob/main/src/utils.ts#L5 const _rebaseHtmlElement = (el: Element, attr: string, newBase: string | URL) => { const rebased = new URL(el.getAttribute(attr)!, newBase) el.setAttribute(attr, rebased.pathname + rebased.hash) } export function normalizeRelativeURLs(el: Element | Document, destination: string | URL) { el.querySelectorAll('[href=""], [href^="./"], [href^="../"]').forEach((item) => _rebaseHtmlElement(item, "href", destination), ) el.querySelectorAll('[src=""], [src^="./"], [src^="../"]').forEach((item) => _rebaseHtmlElement(item, "src", destination), ) } const _rebaseHastElement = ( el: HastElement, attr: string, curBase: FullSlug, newBase: FullSlug, ) => { if (el.properties?.[attr]) { if (!isRelativeURL(String(el.properties[attr]))) { return } const rel = joinSegments(resolveRelative(curBase, newBase), "..", el.properties[attr] as string) el.properties[attr] = rel } } export function normalizeHastElement(rawEl: HastElement, curBase: FullSlug, newBase: FullSlug) { const el = clone(rawEl) // clone so we dont modify the original page _rebaseHastElement(el, "src", curBase, newBase) _rebaseHastElement(el, "href", curBase, newBase) if (el.children) { el.children = el.children.map((child) => normalizeHastElement(child as HastElement, curBase, newBase), ) } return el } // resolve /a/b/c to ../.. export function pathToRoot(slug: FullSlug): RelativeURL { let rootPath = slug .split("/") .filter((x) => x !== "") .slice(0, -1) .map((_) => "..") .join("/") if (rootPath.length === 0) { rootPath = "." } return rootPath as RelativeURL } export function resolveRelative(current: FullSlug, target: FullSlug | SimpleSlug): RelativeURL { const res = joinSegments(pathToRoot(current), simplifySlug(target as FullSlug)) as RelativeURL return res } export function splitAnchor(link: string): [string, string] { let [fp, anchor] = link.split("#", 2) if (fp.endsWith(".pdf")) { return [fp, anchor === undefined ? "" : `#${anchor}`] } anchor = anchor === undefined ? "" : "#" + slugAnchor(anchor) return [fp, anchor] } export function slugTag(tag: string) { return tag .split("/") .map((tagSegment) => sluggify(tagSegment)) .join("/") } export function joinSegments(...args: string[]): string { if (args.length === 0) { return "" } let joined = args .filter((segment) => segment !== "" && segment !== "/") .map((segment) => stripSlashes(segment)) .join("/") // if the first segment starts with a slash, add it back if (args[0].startsWith("/")) { joined = "/" + joined } // if the last segment is a folder, add a trailing slash if (args[args.length - 1].endsWith("/")) { joined = joined + "/" } return joined } export function getAllSegmentPrefixes(tags: string): string[] { const segments = tags.split("/") const results: string[] = [] for (let i = 0; i < segments.length; i++) { results.push(segments.slice(0, i + 1).join("/")) } return results } export interface TransformOptions { strategy: "absolute" | "relative" | "shortest" allSlugs: FullSlug[] } export function transformLink(src: FullSlug, target: string, opts: TransformOptions): RelativeURL { let targetSlug = transformInternalLink(target) if (opts.strategy === "relative") { return targetSlug as RelativeURL } else { const folderTail = isFolderPath(targetSlug) ? "/" : "" const canonicalSlug = stripSlashes(targetSlug.slice(".".length)) let [targetCanonical, targetAnchor] = splitAnchor(canonicalSlug) if (opts.strategy === "shortest") { // if the file name is unique, then it's just the filename const matchingFileNames = opts.allSlugs.filter((slug) => { const parts = slug.split("/") const fileName = parts.at(-1) return targetCanonical === fileName }) // only match, just use it if (matchingFileNames.length === 1) { const targetSlug = matchingFileNames[0] return (resolveRelative(src, targetSlug) + targetAnchor) as RelativeURL } } // if it's not unique, then it's the absolute path from the vault root return (joinSegments(pathToRoot(src), canonicalSlug) + folderTail) as RelativeURL } } // path helpers export function isFolderPath(fplike: string): boolean { return ( fplike.endsWith("/") || endsWith(fplike, "index") || endsWith(fplike, "index.md") || endsWith(fplike, "index.html") ) } export function endsWith(s: string, suffix: string): boolean { return s === suffix || s.endsWith("/" + suffix) } export function trimSuffix(s: string, suffix: string): string { if (endsWith(s, suffix)) { s = s.slice(0, -suffix.length) } return s } function containsForbiddenCharacters(s: string): boolean { return s.includes(" ") || s.includes("#") || s.includes("?") || s.includes("&") } function _hasFileExtension(s: string): boolean { return getFileExtension(s) !== undefined } export function getFileExtension(s: string): string | undefined { return s.match(/\.[A-Za-z0-9]+$/)?.[0] } function isRelativeSegment(s: string): boolean { return /^\.{0,2}$/.test(s) } export function stripSlashes(s: string, onlyStripPrefix?: boolean): string { if (s.startsWith("/")) { s = s.substring(1) } if (!onlyStripPrefix && s.endsWith("/")) { s = s.slice(0, -1) } return s } function _addRelativeToStart(s: string): string { if (s === "") { s = "." } if (!s.startsWith(".")) { s = joinSegments(".", s) } return s } ================================================ FILE: quartz/util/perf.ts ================================================ import pretty from "pretty-time" import { styleText } from "util" export class PerfTimer { evts: { [key: string]: [number, number] } constructor() { this.evts = {} this.addEvent("start") } addEvent(evtName: string) { this.evts[evtName] = process.hrtime() } timeSince(evtName?: string): string { return styleText("yellow", pretty(process.hrtime(this.evts[evtName ?? "start"]))) } } ================================================ FILE: quartz/util/random.ts ================================================ export function randomIdNonSecure() { return Math.random().toString(36).substring(2, 8) } ================================================ FILE: quartz/util/resources.tsx ================================================ import { randomUUID } from "crypto" import { JSX } from "preact/jsx-runtime" import { QuartzPluginData } from "../plugins/vfile" export type JSResource = { loadTime: "beforeDOMReady" | "afterDOMReady" moduleType?: "module" spaPreserve?: boolean } & ( | { src: string contentType: "external" } | { script: string contentType: "inline" } ) export type CSSResource = { content: string inline?: boolean spaPreserve?: boolean } export function JSResourceToScriptElement(resource: JSResource, preserve?: boolean): JSX.Element { const scriptType = resource.moduleType ?? "application/javascript" const spaPreserve = preserve ?? resource.spaPreserve if (resource.contentType === "external") { return ( ) } } export function CSSResourceToStyleElement(resource: CSSResource, preserve?: boolean): JSX.Element { const spaPreserve = preserve ?? resource.spaPreserve if (resource.inline ?? false) { return } else { return ( ) } } export interface StaticResources { css: CSSResource[] js: JSResource[] additionalHead: (JSX.Element | ((pageData: QuartzPluginData) => JSX.Element))[] } export type StringResource = string | string[] | undefined export function concatenateResources(...resources: StringResource[]): StringResource { return resources .filter((resource): resource is string | string[] => resource !== undefined) .flat() } ================================================ FILE: quartz/util/sourcemap.ts ================================================ import fs from "fs" import sourceMapSupport from "source-map-support" import { fileURLToPath } from "url" export const options: sourceMapSupport.Options = { // source map hack to get around query param // import cache busting retrieveSourceMap(source) { if (source.includes(".quartz-cache")) { let realSource = fileURLToPath(source.split("?", 2)[0] + ".map") return { map: fs.readFileSync(realSource, "utf8"), } } else { return null } }, } ================================================ FILE: quartz/util/theme.ts ================================================ export interface ColorScheme { light: string lightgray: string gray: string darkgray: string dark: string secondary: string tertiary: string highlight: string textHighlight: string } interface Colors { lightMode: ColorScheme darkMode: ColorScheme } export type FontSpecification = | string | { name: string weights?: number[] includeItalic?: boolean } export interface Theme { typography: { title?: FontSpecification header: FontSpecification body: FontSpecification code: FontSpecification } cdnCaching: boolean colors: Colors fontOrigin: "googleFonts" | "local" } export type ThemeKey = keyof Colors const DEFAULT_SANS_SERIF = 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"' const DEFAULT_MONO = "ui-monospace, SFMono-Regular, SF Mono, Menlo, monospace" export function getFontSpecificationName(spec: FontSpecification): string { if (typeof spec === "string") { return spec } return spec.name } function formatFontSpecification( type: "title" | "header" | "body" | "code", spec: FontSpecification, ) { if (typeof spec === "string") { spec = { name: spec } } const defaultIncludeWeights = type === "header" ? [400, 700] : [400, 600] const defaultIncludeItalic = type === "body" const weights = spec.weights ?? defaultIncludeWeights const italic = spec.includeItalic ?? defaultIncludeItalic const features: string[] = [] if (italic) { features.push("ital") } if (weights.length > 1) { const weightSpec = italic ? weights .flatMap((w) => [`0,${w}`, `1,${w}`]) .sort() .join(";") : weights.join(";") features.push(`wght@${weightSpec}`) } if (features.length > 0) { return `${spec.name}:${features.join(",")}` } return spec.name } export function googleFontHref(theme: Theme) { const { header, body, code } = theme.typography const headerFont = formatFontSpecification("header", header) const bodyFont = formatFontSpecification("body", body) const codeFont = formatFontSpecification("code", code) return `https://fonts.googleapis.com/css2?family=${headerFont}&family=${bodyFont}&family=${codeFont}&display=swap` } export function googleFontSubsetHref(theme: Theme, text: string) { const title = theme.typography.title || theme.typography.header const titleFont = formatFontSpecification("title", title) return `https://fonts.googleapis.com/css2?family=${titleFont}&text=${encodeURIComponent(text)}&display=swap` } export interface GoogleFontFile { url: string filename: string extension: string } const fontMimeMap: Record = { truetype: "ttf", woff: "woff", woff2: "woff2", opentype: "otf", } export async function processGoogleFonts( stylesheet: string, baseUrl: string, ): Promise<{ processedStylesheet: string fontFiles: GoogleFontFile[] }> { const fontSourceRegex = /url\((https:\/\/fonts.gstatic.com\/.+(?:\/|(?:kit=))(.+?)[.&].+?)\)\sformat\('(\w+?)'\);/g const fontFiles: GoogleFontFile[] = [] let processedStylesheet = stylesheet let match while ((match = fontSourceRegex.exec(stylesheet)) !== null) { const url = match[1] const filename = match[2] const extension = fontMimeMap[match[3].toLowerCase()] const staticUrl = `https://${baseUrl}/static/fonts/${filename}.${extension}` processedStylesheet = processedStylesheet.replace(url, staticUrl) fontFiles.push({ url, filename, extension }) } return { processedStylesheet, fontFiles } } export function joinStyles(theme: Theme, ...stylesheet: string[]) { return ` ${stylesheet.join("\n\n")} :root { --light: ${theme.colors.lightMode.light}; --lightgray: ${theme.colors.lightMode.lightgray}; --gray: ${theme.colors.lightMode.gray}; --darkgray: ${theme.colors.lightMode.darkgray}; --dark: ${theme.colors.lightMode.dark}; --secondary: ${theme.colors.lightMode.secondary}; --tertiary: ${theme.colors.lightMode.tertiary}; --highlight: ${theme.colors.lightMode.highlight}; --textHighlight: ${theme.colors.lightMode.textHighlight}; --titleFont: "${getFontSpecificationName(theme.typography.title || theme.typography.header)}", ${DEFAULT_SANS_SERIF}; --headerFont: "${getFontSpecificationName(theme.typography.header)}", ${DEFAULT_SANS_SERIF}; --bodyFont: "${getFontSpecificationName(theme.typography.body)}", ${DEFAULT_SANS_SERIF}; --codeFont: "${getFontSpecificationName(theme.typography.code)}", ${DEFAULT_MONO}; } :root[saved-theme="dark"] { --light: ${theme.colors.darkMode.light}; --lightgray: ${theme.colors.darkMode.lightgray}; --gray: ${theme.colors.darkMode.gray}; --darkgray: ${theme.colors.darkMode.darkgray}; --dark: ${theme.colors.darkMode.dark}; --secondary: ${theme.colors.darkMode.secondary}; --tertiary: ${theme.colors.darkMode.tertiary}; --highlight: ${theme.colors.darkMode.highlight}; --textHighlight: ${theme.colors.darkMode.textHighlight}; } ` } ================================================ FILE: quartz/util/trace.ts ================================================ import { styleText } from "util" import process from "process" import { isMainThread } from "workerpool" const rootFile = /.*at file:/ export function trace(msg: string, err: Error) { let stack = err.stack ?? "" const lines: string[] = [] lines.push("") lines.push( "\n" + styleText(["bgRed", "black", "bold"], " ERROR ") + "\n\n" + styleText("red", ` ${msg}`) + (err.message.length > 0 ? `: ${err.message}` : ""), ) let reachedEndOfLegibleTrace = false for (const line of stack.split("\n").slice(1)) { if (reachedEndOfLegibleTrace) { break } if (!line.includes("node_modules")) { lines.push(` ${line}`) if (rootFile.test(line)) { reachedEndOfLegibleTrace = true } } } const traceMsg = lines.join("\n") if (!isMainThread) { // gather lines and throw throw new Error(traceMsg) } else { // print and exit console.error(traceMsg) process.exit(1) } } ================================================ FILE: quartz/worker.ts ================================================ import sourceMapSupport from "source-map-support" sourceMapSupport.install(options) import cfg from "../quartz.config" import { BuildCtx, WorkerSerializableBuildCtx } from "./util/ctx" import { FilePath } from "./util/path" import { createFileParser, createHtmlProcessor, createMarkdownParser, createMdProcessor, } from "./processors/parse" import { options } from "./util/sourcemap" import { MarkdownContent, ProcessedContent } from "./plugins/vfile" // only called from worker thread export async function parseMarkdown( partialCtx: WorkerSerializableBuildCtx, fps: FilePath[], ): Promise { const ctx: BuildCtx = { ...partialCtx, cfg, } return await createFileParser(ctx, fps)(createMdProcessor(ctx)) } // only called from worker thread export function processHtml( partialCtx: WorkerSerializableBuildCtx, mds: MarkdownContent[], ): Promise { const ctx: BuildCtx = { ...partialCtx, cfg, } return createMarkdownParser(ctx, mds)(createHtmlProcessor(ctx)) } ================================================ FILE: quartz.config.ts ================================================ import { QuartzConfig } from "./quartz/cfg" import * as Plugin from "./quartz/plugins" /** * Quartz 4 Configuration * * See https://quartz.jzhao.xyz/configuration for more information. */ const config: QuartzConfig = { configuration: { pageTitle: "Quartz 4", pageTitleSuffix: "", enableSPA: true, enablePopovers: true, analytics: { provider: "plausible", }, locale: "en-US", baseUrl: "quartz.jzhao.xyz", ignorePatterns: ["private", "templates", ".obsidian"], defaultDateType: "modified", theme: { fontOrigin: "googleFonts", cdnCaching: true, typography: { header: "Schibsted Grotesk", body: "Source Sans Pro", code: "IBM Plex Mono", }, colors: { lightMode: { light: "#faf8f8", lightgray: "#e5e5e5", gray: "#b8b8b8", darkgray: "#4e4e4e", dark: "#2b2b2b", secondary: "#284b63", tertiary: "#84a59d", highlight: "rgba(143, 159, 169, 0.15)", textHighlight: "#fff23688", }, darkMode: { light: "#161618", lightgray: "#393639", gray: "#646464", darkgray: "#d4d4d4", dark: "#ebebec", secondary: "#7b97aa", tertiary: "#84a59d", highlight: "rgba(143, 159, 169, 0.15)", textHighlight: "#b3aa0288", }, }, }, }, plugins: { transformers: [ Plugin.FrontMatter(), Plugin.CreatedModifiedDate({ priority: ["frontmatter", "git", "filesystem"], }), Plugin.SyntaxHighlighting({ theme: { light: "github-light", dark: "github-dark", }, keepBackground: false, }), Plugin.ObsidianFlavoredMarkdown({ enableInHtmlEmbed: false }), Plugin.GitHubFlavoredMarkdown(), Plugin.TableOfContents(), Plugin.CrawlLinks({ markdownLinkResolution: "shortest" }), Plugin.Description(), Plugin.Latex({ renderEngine: "katex" }), ], filters: [Plugin.RemoveDrafts()], emitters: [ Plugin.AliasRedirects(), Plugin.ComponentResources(), Plugin.ContentPage(), Plugin.FolderPage(), Plugin.TagPage(), Plugin.ContentIndex({ enableSiteMap: true, enableRSS: true, }), Plugin.Assets(), Plugin.Static(), Plugin.Favicon(), Plugin.NotFoundPage(), // Comment out CustomOgImages to speed up build time Plugin.CustomOgImages(), ], }, } export default config ================================================ FILE: quartz.layout.ts ================================================ import { PageLayout, SharedLayout } from "./quartz/cfg" import * as Component from "./quartz/components" // components shared across all pages export const sharedPageComponents: SharedLayout = { head: Component.Head(), header: [], afterBody: [], footer: Component.Footer({ links: { GitHub: "https://github.com/jackyzha0/quartz", "Discord Community": "https://discord.gg/cRFFHYye7t", }, }), } // components for pages that display a single page (e.g. a single note) export const defaultContentPageLayout: PageLayout = { beforeBody: [ Component.ConditionalRender({ component: Component.Breadcrumbs(), condition: (page) => page.fileData.slug !== "index", }), Component.ArticleTitle(), Component.ContentMeta(), Component.TagList(), ], left: [ Component.PageTitle(), Component.MobileOnly(Component.Spacer()), Component.Flex({ components: [ { Component: Component.Search(), grow: true, }, { Component: Component.Darkmode() }, { Component: Component.ReaderMode() }, ], }), Component.Explorer(), ], right: [ Component.Graph(), Component.DesktopOnly(Component.TableOfContents()), Component.Backlinks(), ], } // components for pages that display lists of pages (e.g. tags or folders) export const defaultListPageLayout: PageLayout = { beforeBody: [Component.Breadcrumbs(), Component.ArticleTitle(), Component.ContentMeta()], left: [ Component.PageTitle(), Component.MobileOnly(Component.Spacer()), Component.Flex({ components: [ { Component: Component.Search(), grow: true, }, { Component: Component.Darkmode() }, ], }), Component.Explorer(), ], right: [], } ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { "lib": ["esnext", "DOM", "DOM.Iterable"], "experimentalDecorators": true, "module": "esnext", "target": "esnext", "moduleResolution": "node", "strict": true, "incremental": true, "resolveJsonModule": true, "skipLibCheck": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "noUnusedLocals": true, "noUnusedParameters": true, "esModuleInterop": true, "jsx": "react-jsx", "jsxImportSource": "preact" }, "include": ["**/*.ts", "**/*.tsx", "./package.json"], "exclude": ["build/**/*.d.ts"] }