Skip to content

Commit b48d35a

Browse files
committed
feat(docs): enable image fallback hints and upgrade plugin to 0.2.0
1 parent c0f944a commit b48d35a

5 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎docs/.vitepress/theme/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import '@binarynoir/vitepress-markdown-tags/style.css';
55
import { enableGlossaryTooltips } from 'markdown-it-glossary/client';
66
import { enableHtmlEscapeHints } from '@binarynoir/vitepress-html-escape/client';
77
import { enableBrokenLinkHints } from '@binarynoir/vitepress-broken-links/client';
8+
import { enableImageFallbackHints } from '@binarynoir/vite-plugin-image-fallback/client';
89
import './custom.css';
910

1011
export default {
@@ -18,5 +19,7 @@ export default {
1819
enableHtmlEscapeHints();
1920
// Wavy underlines and popovers on links to pages that don't exist.
2021
enableBrokenLinkHints();
22+
// Dashed outlines and popovers on placeholders for images that are missing.
23+
enableImageFallbackHints();
2124
},
2225
} satisfies Theme;

‎docs/guide/how-this-site-works.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ docs/
4646
| Pages left out by `.exclude` | [Exclude](/plugins/exclude/) | `srcExclude` and `vite.plugins` |
4747
| `README.md` as a folder's index | [README Index](/plugins/readme-index/) | `rewrites` and `markdown.config` |
4848
| Smaller images | [Optimize Images](/plugins/optimize-images) | `vite.plugins` |
49-
| Placeholder for a missing image | [Image Fallback](/plugins/image-fallback) | `vite.plugins` |
49+
| Placeholder for a missing image | [Image Fallback](/plugins/image-fallback) | `vite.plugins`, plus the theme |
5050

5151
## The config
5252

5353
<<< @/.vitepress/config.mts{ts}
5454

5555
## The theme
5656

57-
The theme registers the badge component and loads its stylesheet, and turns on the three popovers: glossary definitions, the HTML Escape hints that explain broken markup, and the Broken Links hints that explain dead links:
57+
The theme registers the badge component and loads its stylesheet, and turns on the four popovers: glossary definitions, the HTML Escape hints that explain broken markup, the Broken Links hints that explain dead links, and the Image Fallback hints that explain missing images:
5858

5959
<<< @/.vitepress/theme/index.ts{ts}
6060

‎docs/plugins/image-fallback.md‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ The image below points at a file that does not exist on purpose: `./missing-imag
1818

1919
![This image is intentionally missing to demonstrate the fallback](./missing-image-demo.png)
2020

21-
When you run the build or look at the deploy log, you will see the warning for it. That warning is the plugin working as designed.
21+
Hover the placeholder, or click or tap it, to see what is missing and where it was imported from. When you run the build or look at the deploy log, you will see the same file and line in the warning:
22+
23+
```txt
24+
[vite-plugin-image-fallback] Could not find …/docs/plugins/missing-image-demo.png (imported by plugins/image-fallback.md:19). Using fallback image.
25+
```
26+
27+
That warning is the plugin working as designed.
2228

2329
## Install
2430

@@ -46,6 +52,7 @@ Only relative (`./foo.png`) and root-relative (`/foo.png`) imports are intercept
4652
| `extensions` | `jpg, jpeg, png, gif, svg, webp, avif` | Extensions treated as image imports. |
4753
| `fallback` | gray "Missing Image Asset" SVG | A data URI, or any URL string Vite can serve. |
4854
| `silent` | `false` | Suppress the console warning. |
55+
| `hints` | `true` | Record what is missing, for the hints below. |
4956

5057
```ts
5158
imageFallbackPlugin({
@@ -54,4 +61,25 @@ imageFallbackPlugin({
5461
});
5562
```
5663

64+
## Hints
65+
66+
Turn on the popovers in your theme. They work the same way as [Broken Links](/plugins/broken-links) and [HTML Escape's hints](/plugins/html-escape/#hints), and all three run side by side on this site.
67+
68+
```ts
69+
// .vitepress/theme/index.ts
70+
import DefaultTheme from 'vitepress/theme';
71+
import { enableImageFallbackHints } from '@binarynoir/vite-plugin-image-fallback/client';
72+
73+
export default {
74+
extends: DefaultTheme,
75+
enhanceApp() {
76+
enableImageFallbackHints();
77+
},
78+
};
79+
```
80+
81+
Each placeholder gets a dashed outline and a popover that names the missing import, and the file and line that imported it. The plugin records them in a `#image-fallback=…` fragment on the placeholder's URL, which the browser ignores when it loads the image.
82+
83+
`enableImageFallbackHints(options)` takes `hover` (default `true`), `hoverDelay` (default `300` milliseconds) and `injectStyles` (default `true`), the same options as Broken Links. The colors follow the VitePress theme and can be changed with the `--image-fallback-hint-error` CSS variable.
84+
5785
[Source and full README on GitHub](https://github.com/binarynoir/vite-plugin-image-fallback)

‎package-lock.json‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"format:check": "prettier --check ."
2323
},
2424
"devDependencies": {
25-
"@binarynoir/vite-plugin-image-fallback": "^0.1.9",
25+
"@binarynoir/vite-plugin-image-fallback": "^0.2.0",
2626
"@binarynoir/vite-plugin-optimize-images": "^0.1.9",
2727
"@binarynoir/vitepress-auto-navbar": "^0.3.0",
2828
"@binarynoir/vitepress-auto-sidebar": "^0.5.0",

0 commit comments

Comments
 (0)