vite-plugin-vanjs 0.1.20 → 0.1.22

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/meta/tags.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import van from "vanjs-core";
2
2
  import { addMeta } from "./Head.mjs";
3
3
 
4
- /** @typedef {import("vanjs-core").PropsWithKnownKeys} PropsWithKnownKeys */
4
+ /** @typedef {import("./types.d.ts").SupportedTags} SupportedTags */
5
+ /** @typedef {import("vanjs-core").PropsWithKnownKeys<T = SupportedTags>} PropsWithKnownKeys<T> */
5
6
  /** @typedef {import("./types.d.ts").TagProps} TagProps */
6
7
 
7
8
  /**
@@ -31,9 +32,25 @@ export const Meta = (props) => {
31
32
  export const Link = (props) => {
32
33
  const { link } = van.tags;
33
34
  if (props.rel === "stylesheet") {
34
- console.warn("Link doesn't support stylesheets.");
35
+ console.warn("Link doesn't support stylesheets, check the Wiki.");
35
36
  } else {
36
37
  addMeta(link(props));
37
38
  }
38
39
  return null;
39
40
  };
41
+
42
+ /**
43
+ * Add a new `<script>` tag, not to be used for .js files
44
+ * Only to be used as `<script type="application/ld+json">`
45
+ * for SEO purposes.
46
+ * @type {(props: PropsWithKnownKeys<HTMLScriptElement>, content: string) => null}
47
+ */
48
+ export const Script = (props, content) => {
49
+ const { script } = van.tags;
50
+ if (!props.type || props.type !== "application/ld+json") {
51
+ console.warn("Script doesn't support this type, check the Wiki.");
52
+ } else {
53
+ addMeta(script(props, content));
54
+ }
55
+ return null;
56
+ };
package/meta/types.d.ts CHANGED
@@ -15,6 +15,7 @@ export const initializeHeadTags: () => void | (() => Promise<void>);
15
15
  export type SupportedTags =
16
16
  | HTMLTitleElement
17
17
  | HTMLLinkElement
18
+ | HTMLScriptElement
18
19
  | HTMLMetaElement;
19
20
 
20
21
  export type AllHeadTags =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vanjs",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "author": "thednp",
5
5
  "license": "MIT",
6
6
  "description": "An async first mini meta-framework for VanJS powered by Vite",
@@ -65,14 +65,18 @@ export const executeLifecycle = async (route, params) => {
65
65
  const preload = route.preload;
66
66
  const load = route.load;
67
67
 
68
+ const pathname = routerState.pathname;
69
+ const cacheKey = Object.keys(params || {}).length === 0
70
+ ? ""
71
+ : JSON.stringify(params);
72
+
68
73
  if (preload) await preload(params);
69
- if (!data && load) data = await load(params);
74
+ if (!data && load && !dataCache.has(pathname, cacheKey)) {
75
+ data = await load(params);
76
+ } else if (load && dataCache.has(pathname, cacheKey)) {
77
+ dataCache.touch(pathname);
78
+ }
70
79
  if (data) {
71
- // initialLoaded = true;
72
- const pathname = routerState.pathname;
73
- const cacheKey = Object.keys(params || {}).length === 0
74
- ? ""
75
- : JSON.stringify(params);
76
80
  dataCache.set(pathname, cacheKey, {
77
81
  data,
78
82
  error: null,
package/server/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { basename } from "node:path";
2
- // import { routerState } from "../router/index.mjs";
3
2
  import * as dataCache from "../router/dataCache.mjs";
4
3
  export * from "../plugin/helpers.mjs";
5
4
 
@@ -20,7 +19,10 @@ export const renderToString = async (inputSource) => {
20
19
  if (typeof source === "boolean") {
21
20
  return String(source);
22
21
  }
23
- if (typeof source === "object" && "render" in source) {
22
+ if (
23
+ source && typeof source === "object" && "render" in source &&
24
+ typeof source.render === "function"
25
+ ) {
24
26
  return source.render();
25
27
  }
26
28
  if (source instanceof Promise) {
@@ -56,6 +58,14 @@ function renderPreloadLink(file) {
56
58
  return `<link rel="preload" href="${file}" as="font" type="font/woff" crossorigin>`;
57
59
  } else if (file.endsWith(".woff2")) {
58
60
  return `<link rel="preload" href="${file}" as="font" type="font/woff2" crossorigin>`;
61
+ } else if (file.endsWith(".gif")) {
62
+ return `<link rel="preload" href="${file}" as="image" type="image/gif" crossorigin>`;
63
+ } else if (file.endsWith(".jpg") || file.endsWith(".jpeg")) {
64
+ return `<link rel="preload" href="${file}" as="image" type="image/jpeg" crossorigin>`;
65
+ } else if (file.endsWith(".png")) {
66
+ return `<link rel="preload" href="${file}" as="image" type="image/png" crossorigin>`;
67
+ } else if (file.endsWith(".webp")) {
68
+ return `<link rel="preload" href="${file}" as="image" type="image/webp" crossorigin>`;
59
69
  } else {
60
70
  console.warn("Render error! File format not recognized: " + file);
61
71
  return "";