nuxt-content-assets 0.10.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,6 +45,21 @@ Almost as much as being in the sea!
45
45
 
46
46
  At build time the module [collates and serves](#how-it-works) assets and content together.
47
47
 
48
+ ### Features
49
+
50
+ User experience:
51
+
52
+ - co-locate assets with content files
53
+ - write relative paths to see preview in editor
54
+
55
+ Developer experience:
56
+
57
+ - works for tags and custom components
58
+ - works in markdown and frontmatter
59
+ - file watching and live reload
60
+ - image size injection
61
+ - zero config
62
+
48
63
  ## Demo
49
64
 
50
65
  To view the demo locally, run:
@@ -88,7 +103,7 @@ Run the dev server or build and local assets should now be served alongside mark
88
103
 
89
104
  Use relative paths anywhere within your documents:
90
105
 
91
- ```mdx
106
+ ```md
92
107
  Images
93
108
  ![image](image.jpg)
94
109
 
@@ -104,7 +119,7 @@ HTML
104
119
 
105
120
  Relative paths can be defined in frontmatter – as long as they are the only value:
106
121
 
107
- ```mdx
122
+ ```md
108
123
  ---
109
124
  title: Portfolio
110
125
  images:
@@ -176,10 +191,10 @@ export default defineNuxtConfig({
176
191
  imageSize: 'style',
177
192
 
178
193
  // treat these extensions as content
179
- contentExtensions: 'mdx? csv ya?ml json',
194
+ contentExtensions: 'md csv ya?ml json',
180
195
 
181
196
  // output debug messages
182
- debug: true,
197
+ debug: false,
183
198
  }
184
199
  })
185
200
  ```
@@ -196,10 +211,10 @@ You can add one or more image size hints to the generated images:
196
211
 
197
212
  Pick from the following switches:
198
213
 
199
- | Switch | What it does |
200
- | ------- | ------------------------------------------------------------ |
201
- | `style` | Adds `style="aspect-ratio:..."` to any `<img>` tag |
202
- | `attrs` | Adds `width` and `height` attributes to any `<img>` tag |
214
+ | Switch | What it does |
215
+ |---------|---------------------------------------------------------------------------|
216
+ | `style` | Adds `style="aspect-ratio:..."` to any `<img>` tag |
217
+ | `attrs` | Adds `width` and `height` attributes to any `<img>` tag |
203
218
  | `url` | Adds a `?width=...&height=...` query string to image paths in frontmatter |
204
219
 
205
220
  Note: if you add `attrs` only, include the following CSS in your app:
@@ -216,7 +231,7 @@ img {
216
231
  This setting tells Nuxt Content to ignore anything that is **not** one of these file extensions:
217
232
 
218
233
  ```
219
- mdx? csv ya?ml json
234
+ md csv ya?ml json
220
235
  ```
221
236
 
222
237
  This way, you can use any **other** file type as an asset, without needing to explicitly configure extensions.
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.10.3"
7
+ "version": "1.0.0"
8
8
  }
package/dist/module.mjs CHANGED
@@ -35,7 +35,7 @@ function deKey(path) {
35
35
 
36
36
  const defaults = {
37
37
  // inject image size into the rendered html
38
- imageSize: "attrs",
38
+ imageSize: "style",
39
39
  // treat these extensions as content
40
40
  contentExtensions: "md csv ya?ml json",
41
41
  // output debug messages
@@ -124,15 +124,15 @@ function getAssetSizes(srcAbs, hints) {
124
124
  if (hints.length && isImage(srcAbs)) {
125
125
  try {
126
126
  const size = getImageSize(srcAbs);
127
- if (hints.includes("style")) {
128
- ratio = `${size.width}/${size.height}`;
129
- }
130
127
  if (hints.includes("attrs")) {
131
128
  width = size.width;
132
129
  height = size.height;
133
130
  }
131
+ if (hints.includes("style")) {
132
+ ratio = `${size.width}/${size.height}`;
133
+ }
134
134
  if (hints.includes("url")) {
135
- query = `?width=${width}&height=${height}`;
135
+ query = `?width=${size.width}&height=${size.height}`;
136
136
  }
137
137
  } catch (err) {
138
138
  warn(`could not read image "${srcAbs}`);
@@ -319,8 +319,10 @@ async function setupSocketServer(channel, handler) {
319
319
  });
320
320
  nuxt._socketServer = server;
321
321
  server.on("upgrade", ws.serve);
322
+ const wsUrl = url.replace("http", "ws");
323
+ log(`Websocket listening on "${wsUrl}"`);
322
324
  nitro.options.runtimeConfig.public.sockets = {
323
- wsUrl: url.replace("http", "ws")
325
+ wsUrl
324
326
  };
325
327
  nitro.hooks.hook("close", async () => {
326
328
  await ws.close();
@@ -1,7 +1,7 @@
1
1
  import { matchTokens } from "./utils/string.mjs";
2
2
  export const defaults = {
3
3
  // inject image size into the rendered html
4
- imageSize: "attrs",
4
+ imageSize: "style",
5
5
  // treat these extensions as content
6
6
  contentExtensions: "md csv ya?ml json",
7
7
  // output debug messages
@@ -19,15 +19,15 @@ export function getAssetSizes(srcAbs, hints) {
19
19
  if (hints.length && isImage(srcAbs)) {
20
20
  try {
21
21
  const size = getImageSize(srcAbs);
22
- if (hints.includes("style")) {
23
- ratio = `${size.width}/${size.height}`;
24
- }
25
22
  if (hints.includes("attrs")) {
26
23
  width = size.width;
27
24
  height = size.height;
28
25
  }
26
+ if (hints.includes("style")) {
27
+ ratio = `${size.width}/${size.height}`;
28
+ }
29
29
  if (hints.includes("url")) {
30
- query = `?width=${width}&height=${height}`;
30
+ query = `?width=${size.width}&height=${size.height}`;
31
31
  }
32
32
  } catch (err) {
33
33
  warn(`could not read image "${srcAbs}`);
@@ -1,5 +1,6 @@
1
1
  import { Callback } from '../../types';
2
2
  export declare function createWebSocket(): {
3
+ connect: (retry?: boolean) => void;
3
4
  send: (data: any) => void;
4
5
  addHandler(callback: Callback): void;
5
6
  } | null;
@@ -46,10 +46,17 @@ export function createWebSocket() {
46
46
  ws.send(JSON.stringify(data));
47
47
  }
48
48
  };
49
+ let retries = 0;
50
+ const url = useRuntimeConfig().public.sockets?.wsUrl;
49
51
  const connect = (retry = false) => {
50
52
  if (retry) {
51
- logger.log("WS reconnecting..");
52
- setTimeout(connect, 1e3);
53
+ retries++;
54
+ if (retries < 5) {
55
+ logger.log("Reconnecting...");
56
+ setTimeout(connect, 1e3);
57
+ } else {
58
+ logger.warn("Giving up!");
59
+ }
53
60
  return;
54
61
  }
55
62
  if (ws) {
@@ -59,10 +66,9 @@ export function createWebSocket() {
59
66
  }
60
67
  ws = void 0;
61
68
  }
62
- const url = useRuntimeConfig().public.sockets?.wsUrl;
63
69
  if (url) {
64
70
  const wsUrl = `${url}ws`;
65
- logger.log(`Running on ${wsUrl}`);
71
+ logger.log(`WS connect to ${wsUrl}`);
66
72
  ws = new WebSocket(wsUrl);
67
73
  ws.onopen = onOpen;
68
74
  ws.onmessage = onMessage;
@@ -74,6 +80,7 @@ export function createWebSocket() {
74
80
  connect();
75
81
  }
76
82
  return {
83
+ connect,
77
84
  send,
78
85
  addHandler(callback) {
79
86
  if (typeof callback === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-content-assets",
3
- "version": "0.10.3",
3
+ "version": "1.0.0",
4
4
  "description": "Enable locally-located assets in Nuxt Content",
5
5
  "repository": "davestewart/nuxt-content-assets",
6
6
  "license": "MIT",