@tideworthy/tidysites 0.1.4 → 0.1.5

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
@@ -27,7 +27,7 @@ nothing else; it lives in `.tidysites/key`, which is kept out of git.
27
27
  | `tidysites page <path> [--html]` | the rendered page, section by section, with the key each section carries |
28
28
  | `tidysites schema [type or collection]` | the section types and layouts, or one type's or collection's fields |
29
29
  | `tidysites gallery [type]` | a screenshot of every section type and layout in this website's theme, or the first screen of one type |
30
- | `tidysites fetch <url> [--out dir]` | a page of the site being ported: cleaned HTML, its outline (headings, navigation, images, phones, fonts, colours) and its stylesheets |
30
+ | `tidysites fetch <url> [--out dir]` | a page of the site being ported: cleaned HTML, its outline (headings, navigation, images, phones, fonts, the stylesheet's own variables and colours) and its stylesheets, inline style blocks included |
31
31
  | `tidysites rm <collection>/<slug> ...` | delete entry files with their sidecars (`services/*` for every entry of a collection); `push --prune` then removes them from the website |
32
32
  | `tidysites publish --yes` | the live site becomes a copy of the preview site |
33
33
 
package/bin/tidysites.mjs CHANGED
@@ -456,6 +456,9 @@ async function fetchCmd(ctx) {
456
456
  /* a stylesheet that will not download is not the port's problem */
457
457
  }
458
458
  }
459
+ // A page that carries its styles inline (Wix, many builders) has no stylesheet to download: read the <style> blocks too.
460
+ const inline = [...html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((m) => m[1]).join('\n');
461
+ if (inline.trim()) { cssTexts.push(inline); writeFileSync(join(outDir, `${base}-inline.css`), inline); }
459
462
  if (cssTexts.length) o.css = cssSummary(cssTexts.join('\n'));
460
463
  writeFileSync(join(outDir, `${base}.raw.html`), html);
461
464
  writeFileSync(join(outDir, `${base}.html`), cleanHtml(html));
package/lib/fetch.mjs CHANGED
@@ -108,11 +108,18 @@ export function cssSummary(css) {
108
108
  const f = m[1].split(',')[0].replace(/["']/g, '').trim();
109
109
  if (f && !/^(inherit|initial|unset|var\()/.test(f)) fonts.set(f, (fonts.get(f) ?? 0) + 1);
110
110
  }
111
- // The site's own names for its colours and fonts, when its stylesheet defines them; a framework's defaults sit below these.
111
+ // The site's own names for its colours and fonts, when its stylesheet defines them; a framework's defaults sit below
112
+ // these. A builder often defines a token as another token (--button-fill: rgb(var(--color_48)); --color_48: 254,96,47):
113
+ // the references are followed so the list reads as colours, and bare channel triplets become rgb().
114
+ const defined = {};
115
+ for (const m of css.matchAll(/--([a-zA-Z][\w-]*)\s*:\s*([^;}]+)/g)) if (!(m[1] in defined)) defined[m[1]] = m[2].trim();
116
+ const resolve = (v, depth = 0) => (depth > 4 ? v : v.replace(/var\(\s*--([\w-]+)\s*(?:,[^)]*)?\)/g, (_, name) => (name in defined ? resolve(defined[name], depth + 1) : `var(--${name})`)));
112
117
  const variables = {};
113
- for (const m of css.matchAll(/--([a-zA-Z][\w-]*)\s*:\s*([^;}]+)/g)) {
114
- const v = m[2].trim();
115
- if (/#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(|font|["'][A-Z][\w ]+["']/i.test(v) && !/^var\(/.test(v)) variables[m[1]] = v;
118
+ for (const [name, raw] of Object.entries(defined)) {
119
+ let v = resolve(raw).replace(/rgba?\(\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\s*\)/g, 'rgb($1,$2,$3)');
120
+ if (/^\d{1,3},\s*\d{1,3},\s*\d{1,3}$/.test(v)) v = `rgb(${v.replace(/\s/g, '')})`;
121
+ if (/var\(/.test(v)) continue;
122
+ if (/#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(|font|["'][A-Z][\w ]+["']/i.test(v)) variables[name] = v;
116
123
  }
117
124
  const top = (map, n) => [...map.entries()].sort((a, b) => b[1] - a[1]).slice(0, n).map(([value, count]) => ({ value, count }));
118
125
  return { colors: top(colors, 12), fonts: top(fonts, 6), variables };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tideworthy/tidysites",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Pull a Tidysites website to files, edit, validate against its content model, push it back, screenshot the result.",
5
5
  "type": "module",
6
6
  "bin": {