Skip to content

Commit 3281939

Browse files
committed
docs: add Downloads plugin page and demo files
1 parent ef19169 commit 3281939

8 files changed

Lines changed: 124 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ It documents BinaryNoir's open-source VitePress plugins, Vite plugins and comman
66

77
## Plugins demonstrated
88

9-
| Package | Role on this site |
10-
| ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
11-
| [`@binarynoir/vitepress-auto-sidebar`](https://github.com/binarynoir/vitepress-auto-sidebar) | Builds the sidebar from the folder tree |
12-
| [`@binarynoir/vitepress-auto-navbar`](https://github.com/binarynoir/vitepress-auto-navbar) | Builds the top navbar from the folder tree |
13-
| [`@binarynoir/vitepress-markdown-tags`](https://github.com/binarynoir/vitepress-markdown-tags) | Status badges and tagged-page lists |
14-
| [`@binarynoir/vitepress-reading-time-tag`](https://github.com/binarynoir/vitepress-reading-time-tag) | `[[readingTime]]` tip blocks |
15-
| [`markdown-it-glossary`](https://github.com/binarynoir/markdown-it-glossary) | Hover definitions from `docs/reference/glossary.md` |
16-
| [`@binarynoir/vite-plugin-optimize-images`](https://github.com/binarynoir/vite-plugin-optimize-images) | Re-compresses images in the build output |
17-
| [`@binarynoir/vite-plugin-image-fallback`](https://github.com/binarynoir/vite-plugin-image-fallback) | Placeholder for missing images (one is missing on purpose) |
9+
| Package | Role on this site |
10+
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
11+
| [`@binarynoir/vitepress-auto-sidebar`](https://github.com/binarynoir/vitepress-auto-sidebar) | Builds the sidebar from the folder tree |
12+
| [`@binarynoir/vitepress-auto-navbar`](https://github.com/binarynoir/vitepress-auto-navbar) | Builds the top navbar from the folder tree |
13+
| [`@binarynoir/vitepress-markdown-tags`](https://github.com/binarynoir/vitepress-markdown-tags) | Status badges and tagged-page lists |
14+
| [`@binarynoir/vitepress-reading-time-tag`](https://github.com/binarynoir/vitepress-reading-time-tag) | `[[readingTime]]` tip blocks |
15+
| [`@binarynoir/vitepress-downloads`](https://github.com/binarynoir/vitepress-downloads) | Downloadable files from a `downloads` folder (not yet wired in here) |
16+
| [`markdown-it-glossary`](https://github.com/binarynoir/markdown-it-glossary) | Hover definitions from `docs/reference/glossary.md` |
17+
| [`@binarynoir/vite-plugin-optimize-images`](https://github.com/binarynoir/vite-plugin-optimize-images) | Re-compresses images in the build output |
18+
| [`@binarynoir/vite-plugin-image-fallback`](https://github.com/binarynoir/vite-plugin-image-fallback) | Placeholder for missing images (one is missing on purpose) |
1819

1920
## Develop
2021

‎docs/.vitepress/config.mts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default defineConfig({
2121
cleanUrls: true,
2222
lastUpdated: true,
2323

24+
// Downloadable files are published as-is, never built as pages.
25+
srcExclude: ['**/downloads/**'],
26+
2427
sitemap: { hostname: SITE_URL },
2528

2629
head: [

‎docs/plugins/.exclude‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
downloads/

‎docs/plugins/.sidebar‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ auto-sidebar.md:Auto Sidebar
55
auto-navbar.md:Auto Navbar
66
markdown-tags.md:Markdown Tags
77
reading-time-tag.md:Reading Time Tag
8+
downloads.md:Downloads
89
glossary.md:Glossary Tooltips
910
optimize-images.md:Optimize Images
1011
image-fallback.md:Image Fallback

‎docs/plugins/downloads.md‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: Downloads
3+
---
4+
5+
# Downloads ((tag|VitePress plugin|blue))
6+
7+
[[readingTime]]
8+
9+
`@binarynoir/vitepress-downloads` turns a folder named `downloads` into downloadable files, linked with a plain relative path. VitePress is built for pages, so a `.sql`, `.zip` or `.xlsx` normally has to be copied into `public/` and linked by an absolute URL. With this plugin the file stays next to the page that uses it.
10+
11+
```txt
12+
docs/tools/ai/
13+
index.md
14+
downloads/
15+
check-access.sql
16+
template.xlsx
17+
```
18+
19+
```md
20+
[Access check script](./downloads/check-access.sql)
21+
```
22+
23+
The file is published at `/tools/ai/downloads/check-access.sql`, and the link downloads it instead of opening a page. It works in `vitepress dev` and `vitepress build`.
24+
25+
## Try it
26+
27+
This page has its own `downloads` folder: `sample.sql` and `sample.md`.
28+
29+
## Install
30+
31+
```sh
32+
npm install --save-dev @binarynoir/vitepress-downloads
33+
```
34+
35+
## Use
36+
37+
```ts
38+
// .vitepress/config.mts
39+
import { defineConfig } from 'vitepress';
40+
import { withDownloads } from '@binarynoir/vitepress-downloads/vitepress';
41+
42+
export default withDownloads(
43+
defineConfig({
44+
// ...your config
45+
}),
46+
);
47+
```
48+
49+
`withDownloads` keeps your existing `srcExclude`, `markdown.config` and `vite.plugins`, so it composes with other wrappers in any order.
50+
51+
## How links work
52+
53+
Links resolve the way any Markdown link does: from the page's own folder, or from the docs root when they start with `/`. A link counts as a download when its target is inside a download folder. Every other link is left to VitePress.
54+
55+
| You write | Result |
56+
| ----------------------------- | --------------------------------------------------------- |
57+
| `[x](./downloads/a.sql)` | Download of `a.sql` in the page's own `downloads` folder. |
58+
| `[x](downloads/a.xlsx)` | The same, without the `./`. |
59+
| `[x](/guide/downloads/z.zip)` | A file from another section, by path from the docs root. |
60+
| `[x](./other-page.md)` | Not a download. VitePress handles it as a page link. |
61+
62+
Files of any type work, including `.md`, `.js` and `.json`. Markdown files inside a download folder are never built as pages.
63+
64+
## Options
65+
66+
| Option | Default | Description |
67+
| ----------- | --------------- | ---------------------------------------------------------------------------------------------------------- |
68+
| `folders` | `["downloads"]` | Folder name or names to publish. Names, not paths, matched at any depth. `files` is a common second. |
69+
| `onMissing` | `"warn"` | A link into a download folder with no file behind it: `"warn"`, `"error"` (fails the build) or `"ignore"`. |
70+
71+
```ts
72+
withDownloads(config, { folders: ['downloads', 'files'], onMissing: 'error' });
73+
```
74+
75+
## Keep downloads out of the sidebar
76+
77+
If the sidebar is generated from the folder tree, a downloadable `notes.md` would show up as a dead sidebar page. With [Auto Sidebar](/plugins/auto-sidebar) and [Auto Navbar](/plugins/auto-navbar), list the folder in an `.exclude` file in the directory that contains it:
78+
79+
```txt
80+
# docs/tools/ai/.exclude
81+
downloads/
82+
```
83+
84+
## Good to know
85+
86+
- **Everything in a download folder is public.** Files are copied into the built site as they are.
87+
- Hidden files such as `.DS_Store`, and `node_modules`, are never published.
88+
- In dev, downloads are served from disk as attachments, so a `.js` or `.ts` file is not turned into a module.
89+
- Folder names are case-sensitive: `Downloads` is not `downloads`.
90+
91+
[Source and full README on GitHub](https://github.com/binarynoir/vitepress-downloads)

‎docs/plugins/downloads/sample.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Sample Markdown Download
2+
3+
This file lives in a `downloads` folder. It is published as a file, not built as a page, and it never appears in the sidebar or navbar.
4+
5+
## Checks
6+
7+
- [ ] The link downloads the file instead of opening a page.
8+
- [ ] This heading does not show up in site search.
9+
- [ ] This file is missing from the sidebar and navbar.
10+
11+
{{ 1 + 1 }} <!-- Vue interpolation: shows literally if the file is not parsed. -->

‎docs/plugins/downloads/sample.sql‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Sample download for the Downloads plugin demo.
2+
-- Served from docs/plugins/downloads/sample.sql.
3+
4+
SELECT 'Hello from BinaryNoir' AS message;

‎docs/plugins/index.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ title: Plugins
66

77
[[readingTime]]
88

9-
Seven small packages that make a documentation site easier to build and nicer to read. Each one does a single job, they share conventions, and they are all running on the site you are looking at.
9+
Eight small packages that make a documentation site easier to build and nicer to read. Each one does a single job and they share conventions. Seven are running on the site you are looking at; Downloads is new and is not wired into this site yet.
1010

1111
| Plugin | Works with | What it does |
1212
| --------------------------------------------- | ---------------------------- | --------------------------------------------------------- |
1313
| [Auto Sidebar](/plugins/auto-sidebar) | VitePress 2 | Builds `themeConfig.sidebar` from your folders. |
1414
| [Auto Navbar](/plugins/auto-navbar) | VitePress 2 | Builds `themeConfig.nav` from your folders. |
1515
| [Markdown Tags](/plugins/markdown-tags/) | VitePress, VS Code, Obsidian | Inline status badges and tagged-pages lists. |
1616
| [Reading Time Tag](/plugins/reading-time-tag) | VitePress 2 | `[[readingTime]]` becomes a reading-time tip block. |
17+
| [Downloads](/plugins/downloads) | VitePress | Files in a `downloads` folder become linkable downloads. |
1718
| [Glossary Tooltips](/plugins/glossary) | VitePress, markdown-it | Hover definitions from one glossary file. |
1819
| [Optimize Images](/plugins/optimize-images) | Vite | Re-compresses images in the build output. |
1920
| [Image Fallback](/plugins/image-fallback) | Vite | Placeholder for missing images instead of a failed build. |
@@ -26,6 +27,7 @@ npm install --save-dev \
2627
@binarynoir/vitepress-auto-navbar \
2728
@binarynoir/vitepress-markdown-tags \
2829
@binarynoir/vitepress-reading-time-tag \
30+
@binarynoir/vitepress-downloads \
2931
@binarynoir/vite-plugin-optimize-images \
3032
@binarynoir/vite-plugin-image-fallback \
3133
markdown-it-glossary

0 commit comments

Comments
 (0)