minista 3.0.0-alpha.21 → 3.0.0-alpha.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/dist/cli/build.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import { parse as parseUrl } from "node:url";
2
3
  import fs from "fs-extra";
3
4
  import pc from "picocolors";
4
5
  import {
@@ -84,27 +85,42 @@ async function build(inlineConfig = {}) {
84
85
  return ssgPages.map((page) => {
85
86
  const pathname = page.path;
86
87
  let parsedHtml = parseHtml(page.html);
87
- const links = parsedHtml.querySelectorAll("link").filter(
88
- (el) => el.getAttribute("href")?.startsWith("/@minista-entry/")
89
- );
90
- const scripts = parsedHtml.querySelectorAll("script").filter(
91
- (el) => el.getAttribute("src")?.startsWith("/@minista-entry/")
92
- );
88
+ function hasEntryFile(src) {
89
+ const isAbsolute = parseUrl(src).protocol;
90
+ if (!src || isAbsolute) {
91
+ return false;
92
+ }
93
+ const filePath = path.join(resolvedRoot, src);
94
+ return fs.existsSync(filePath);
95
+ }
96
+ const links = parsedHtml.querySelectorAll("link").filter((el) => {
97
+ const url = el.getAttribute("href") || "";
98
+ return hasEntryFile(url);
99
+ });
100
+ const scripts = parsedHtml.querySelectorAll("script").filter((el) => {
101
+ const url = el.getAttribute("src") || "";
102
+ return hasEntryFile(url);
103
+ });
93
104
  if (links.length === 0 && scripts.length === 0) {
94
105
  return {
95
106
  fileName: page.fileName,
96
107
  data: page.html
97
108
  };
98
109
  }
99
- function registerSsgEntries(items, srcAttr, outExt, selfEntries, otherEntries) {
110
+ function registerSsgEntries(items, selfEntries, otherEntries) {
100
111
  items.map((item) => {
112
+ const tagName = item.tagName.toLowerCase();
113
+ const isScript = tagName === "script";
114
+ const srcAttr = isScript ? "src" : "href";
115
+ const outExt = isScript ? "js" : "css";
101
116
  let src = "";
102
117
  src = item.getAttribute(srcAttr) || "";
103
- src = src.replace("/@minista-entry/", "");
104
118
  src = path.join(resolvedRoot, src);
105
119
  let name = "";
106
120
  name = item.getAttribute("data-minista-entry-name") || "";
107
121
  name = name ? name : path.parse(src).name;
122
+ let attributes = "";
123
+ attributes = item.getAttribute("data-minista-entry-attributes") || "";
108
124
  let assetPath = "";
109
125
  assetPath = path.join(assets.outDir, name + "." + outExt);
110
126
  assetPath = getBasedAssetPath({
@@ -112,8 +128,25 @@ async function build(inlineConfig = {}) {
112
128
  pathname,
113
129
  assetPath
114
130
  });
131
+ if (isScript && attributes) {
132
+ item.removeAttribute("type");
133
+ }
134
+ if (attributes && attributes !== "false") {
135
+ const attrStrArray = attributes.split(/\s+/);
136
+ let attrObj = {};
137
+ attrStrArray.map((attrStr) => {
138
+ const parts = attrStr.split("=");
139
+ const key = parts[0];
140
+ const value = parts[1].replace(/\"/g, "");
141
+ return attrObj[key] = value;
142
+ });
143
+ for (const key in attrObj) {
144
+ item.setAttribute(key, attrObj[key]);
145
+ }
146
+ }
115
147
  item.setAttribute(srcAttr, assetPath);
116
148
  item.removeAttribute("data-minista-entry-name");
149
+ item.removeAttribute("data-minista-entry-attributes");
117
150
  const duplicateName = `${name}-ministaDuplicateName0`;
118
151
  if (Object.hasOwn(selfEntries, name)) {
119
152
  return;
@@ -129,8 +162,8 @@ async function build(inlineConfig = {}) {
129
162
  return;
130
163
  });
131
164
  }
132
- registerSsgEntries(links, "href", "css", ssgLinks, ssgScripts);
133
- registerSsgEntries(scripts, "src", "js", ssgScripts, ssgLinks);
165
+ registerSsgEntries(links, ssgLinks, ssgScripts);
166
+ registerSsgEntries(scripts, ssgScripts, ssgLinks);
134
167
  const htmlStr = parsedHtml.toString();
135
168
  return {
136
169
  fileName: page.fileName,
@@ -94,10 +94,6 @@ async function resolveViteConfig(mainConfig, subConfig) {
94
94
  find: "/@minista-project-root",
95
95
  replacement: path.resolve(subConfig.resolvedRoot)
96
96
  },
97
- {
98
- find: "/@minista-entry",
99
- replacement: path.resolve(subConfig.resolvedRoot)
100
- },
101
97
  {
102
98
  find: "/@minista-temp",
103
99
  replacement: path.resolve(subConfig.tempDir)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minista",
3
3
  "description": "Static site generator with 100% static export from React and Vite",
4
- "version": "3.0.0-alpha.21",
4
+ "version": "3.0.0-alpha.22",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=16.8.0"