vowel 0.1.1 → 0.1.3

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/.cache.json ADDED
@@ -0,0 +1 @@
1
+ {}
package/bin.js CHANGED
@@ -3,6 +3,14 @@
3
3
  import { execSync, spawn } from 'child_process';
4
4
  import path from 'node:path';
5
5
  import url from 'node:url';
6
+ import pc from 'picocolors';
7
+ import mri from 'mri';
8
+ import filterConsole from 'filter-console';
9
+ import process from 'process';
10
+ import readline from 'readline';
11
+ import logUpdate from 'log-update';
12
+
13
+ const args = mri(process.argv);
6
14
 
7
15
  // Directory where the module is
8
16
  const binURL = import.meta.url;
@@ -12,17 +20,54 @@ const binDirName = path.dirname(binFilePath);
12
20
  // Directory where the command was called
13
21
  const homeDir = process.cwd();
14
22
 
23
+ const spawnArgs = ['./server.js', '--directory', homeDir];
24
+ if (args.build) spawnArgs.push('--build');
25
+
26
+ if (!args.verbose) {
27
+ filterConsole(['jsconfig', 'vite', 'Vite', 'tsconfig', `--host`]);
28
+ console.log(`\n\n`);
29
+ }
30
+
15
31
  // Args: File to run, home directory,
16
- const child = spawn('node', ['./server.js', homeDir, process.argv[2] === 'build'], {
32
+ const child = spawn('node', spawnArgs, {
17
33
  cwd: binDirName
18
34
  });
19
35
 
36
+ let processedFiles = 0;
37
+ let foundFiles = 0;
38
+ const std = process.stdout;
39
+
20
40
  child.stdout.on('data', (data) => {
21
- console.log(`${data}`);
41
+ const message = data.toString();
42
+ if (message.match('fileread')) {
43
+ processedFiles++;
44
+ logUpdate(pc.green(` Files read: ${processedFiles}/${foundFiles}`));
45
+ } else if (message.startsWith('filesfound')) {
46
+ const count = Number(message.split(':').at(-1).slice(0, -1));
47
+ foundFiles += count;
48
+ } else if (message.startsWith('loaded')) {
49
+ logUpdate(pc.green(` Files read: ${foundFiles}/${foundFiles}`));
50
+ console.log(`\n\n`);
51
+ processedFiles = 0;
52
+ foundFiles = 0;
53
+ } else if (message.match('http://localhost:')) {
54
+ const url = message.match(/http:\/\/localhost:\S+/);
55
+ console.log(
56
+ pc.bgCyan(
57
+ pc.bold(`
58
+
59
+ Website: ${url}
60
+ `)
61
+ )
62
+ );
63
+ console.log(`\n`);
64
+ } else {
65
+ console.log(pc.blue(data));
66
+ }
22
67
  });
23
68
 
24
69
  child.stderr.on('data', (data) => {
25
- console.error(`${data}`);
70
+ console.error(pc.red(data));
26
71
  });
27
72
 
28
73
  child.on('close', (code) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vowel",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "bin": "./bin.js",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -20,10 +20,14 @@
20
20
  "@sveltejs/vite-plugin-svelte": "^4.0.0-next.3",
21
21
  "any-date-parser": "^1.5.4",
22
22
  "change-case": "^5.4.1",
23
+ "filter-console": "^1.0.0",
23
24
  "js-yaml": "^4.1.0",
25
+ "loading-cli": "^1.1.2",
26
+ "log-update": "^6.0.0",
24
27
  "milligram": "^1.4.1",
25
28
  "object-path": "^0.11.8",
26
29
  "open-props": "^1.6.13",
30
+ "picocolors": "^1.0.1",
27
31
  "prettier": "^3.0.0",
28
32
  "prettier-plugin-svelte": "^3.0.0",
29
33
  "remark": "^15.0.1",
package/server.js CHANGED
@@ -3,17 +3,18 @@ import { createServer, build } from 'vite';
3
3
  import { writeFile, mkdir, readFile } from 'fs/promises';
4
4
  import { existsSync } from 'fs';
5
5
  import { dirname, join } from 'path';
6
+ import mri from 'mri';
6
7
 
7
- const __dirname = fileURLToPath(new URL('.', import.meta.url));
8
+ const args = mri(process.argv);
9
+ const { build: isBuild, directory } = args;
8
10
 
9
- // Check if this is a package build
10
- const isBuild = process.argv[2] === 'build';
11
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
11
12
 
12
13
  // If this is not a build, read the process argument
13
14
  const arg = !isBuild ? process.argv[2] : false;
14
15
 
15
16
  // Check if this is a user (process argument) or package dev (cwd)
16
- const $home = [arg || join(process.cwd(), 'content')];
17
+ const $home = isBuild ? join(process.cwd(), 'content') : directory;
17
18
 
18
19
  const define = {
19
20
  $home
@@ -73,7 +74,7 @@ async function runServer() {
73
74
  }
74
75
 
75
76
  // If build mode
76
- if (isBuild || process.argv[3] === 'true') {
77
+ if (isBuild) {
77
78
  buildProject();
78
79
  } else {
79
80
  runServer();
@@ -10,7 +10,7 @@
10
10
  */
11
11
  let { props } = $props();
12
12
  // TODO: Normalize frontmatter props
13
- let { properties, website } = $derived(props);
13
+ let { properties, website, format } = $derived(props);
14
14
 
15
15
  const excludedProperties = [
16
16
  'title',
@@ -47,7 +47,7 @@
47
47
  {#if website.hasOwnProperty(key)}
48
48
  <FrontmatterTaxonomy {property} {key} {website} />
49
49
  {:else}
50
- <FrontmatterProperty {property} {key} />
50
+ <FrontmatterProperty {property} {key} {format} />
51
51
  {/if}
52
52
  {/if}
53
53
  {/each}
@@ -4,7 +4,7 @@
4
4
  import Image from './Markdown/Image.svelte';
5
5
 
6
6
  /** @type {{ property: any, key: string }}*/
7
- let { property, key } = $props();
7
+ let { property, key, format } = $props();
8
8
  </script>
9
9
 
10
10
  {#if property}
@@ -30,7 +30,7 @@
30
30
  {#if value.type === 'array'}
31
31
  {@render array(value.output)}
32
32
  {:else if value.type === 'object'}
33
- <Frontmatter props={{ properties: value.output }} />
33
+ <Frontmatter props={{ properties: value.output, format }} />
34
34
  {:else if value.type === 'image'}
35
35
  {@render image(value.output)}
36
36
  {:else if value.type === 'date'}
@@ -52,19 +52,25 @@
52
52
  {/snippet}
53
53
 
54
54
  {#snippet url(value)}
55
- <article>
55
+ {#if format === 'rss'}
56
56
  <a href={value.url}>
57
- {#if value['og:image']}
58
- <img src={value['og:image']} alt="" />
59
- {/if}
60
- <h2>
61
- {value['og:title'] || value.title}
62
- </h2>
63
- <p>
64
- {value['og:description']}
65
- </p>
57
+ {value.title || value['og:title']}
66
58
  </a>
67
- </article>
59
+ {:else}
60
+ <article>
61
+ <a href={value.url}>
62
+ {#if value['og:image']}
63
+ <img src={value['og:image']} alt="" />
64
+ {/if}
65
+ <h2>
66
+ {value.title || value['og:title']}
67
+ </h2>
68
+ <p>
69
+ {value['og:description']}
70
+ </p>
71
+ </a>
72
+ </article>
73
+ {/if}
68
74
  {/snippet}
69
75
 
70
76
  {#snippet pdf(value)}
@@ -11,8 +11,8 @@
11
11
  try {
12
12
  return new URL(url);
13
13
  } catch (e) {
14
- console.error(`Error on image ${url}:`);
15
- console.error(e);
14
+ // console.error(`Error on image ${url}:`);
15
+ // console.error(e);
16
16
  }
17
17
  }
18
18
 
@@ -1,5 +1,5 @@
1
1
  <script>
2
- let { metadata, url } = $props();
2
+ let { metadata, url, format } = $props();
3
3
  let { image, description, author } = $derived(metadata || {});
4
4
 
5
5
  const href = $derived(metadata?.ogURL || metadata?.canonicalURL || url || '');
@@ -10,24 +10,30 @@
10
10
  </script>
11
11
 
12
12
  {#if metadata}
13
- <article class="link-preview">
14
- <a {href}>
15
- {#if image}
16
- <img src={image} alt="" />
17
- {/if}
18
- <h2>{title ? title + ' - ' : ''}<span class="host">{urlObject.host}</span></h2>
19
- {#if author}
20
- <p>
21
- By {author}
22
- </p>
23
- {/if}
24
- {#if description}
25
- <p>
26
- {description}
27
- </p>
28
- {/if}
29
- </a>
30
- </article>
13
+ {#if format === 'rss'}
14
+ <p><a {href}>{title ? title + ' - ' : ''}{urlObject.host}</a></p>
15
+ {:else}
16
+ <article class="link-preview">
17
+ <a {href}>
18
+ {#if image}
19
+ <img src={image} alt="" />
20
+ {/if}
21
+ <h2>{title ? title + ' - ' : ''}<span class="host">{urlObject.host}</span></h2>
22
+ {#if author}
23
+ <p>
24
+ By {author}
25
+ </p>
26
+ {/if}
27
+ {#if description}
28
+ <p>
29
+ {description}
30
+ </p>
31
+ {/if}
32
+ </a>
33
+ </article>
34
+ {/if}
35
+ {:else if format === 'rss'}
36
+ <p><a {href}>{urlObject.host}</a></p>
31
37
  {:else}
32
38
  <article class="link-preview">
33
39
  <a {href}>
@@ -11,7 +11,7 @@
11
11
 
12
12
  let { props } = $props();
13
13
 
14
- let { ast, level, website } = $derived(props);
14
+ let { ast, level, website, format } = $derived(props);
15
15
 
16
16
  function getElement(node) {
17
17
  if (node.type === 'heading') {
@@ -43,7 +43,7 @@
43
43
  <section class={createFolderClass(path)}>
44
44
  {#each pages as page}
45
45
  <article class={createPageClass(page.url, 'thumbnail')}>
46
- <Page link={true} {content} {page} level={level + 1} {website} />
46
+ <Page link={true} {content} {page} level={level + 1} {website} {format} />
47
47
  </article>
48
48
  {/each}
49
49
  </section>
@@ -55,6 +55,7 @@
55
55
  level={level + 1}
56
56
  {website}
57
57
  content={false}
58
+ {format}
58
59
  />
59
60
  </article>
60
61
  {:else if node.type === 'heading'}
@@ -62,16 +63,16 @@
62
63
  <svelte:self props={{ ast: node.children, level }} />
63
64
  </svelte:element>
64
65
  {:else if node.type === 'link' && node.children}
65
- <Link {node} {level} {website} />
66
+ <Link {node} {level} {website} {format} />
66
67
  {:else if node.type === 'thematicBreak'}
67
68
  <hr />
68
69
  {:else if node.type === 'image'}
69
70
  <Image {node} />
70
71
  {:else if node.type === 'url'}
71
- <LinkPreview url={node.value} metadata={node.metadata} />
72
+ <LinkPreview url={node.value} metadata={node.metadata} {format} />
72
73
  {:else if node.children}
73
74
  <svelte:element this={getElement(node)}>
74
- <svelte:self props={{ ast: node.children, level }} />
75
+ <svelte:self props={{ ast: node.children, level, format }} />
75
76
  </svelte:element>
76
77
  {:else if node.type === 'text'}
77
78
  <Text {node} />
@@ -46,7 +46,7 @@
46
46
  <time datetime={dateObject.toISOString()}>{dateObject.toLocaleDateString()}</time>
47
47
  {/if}
48
48
 
49
- <Frontmatter props={{ properties: page, website }} />
49
+ <Frontmatter props={{ properties: page, website, format }} />
50
50
 
51
51
  {#if page?.description || (!content && page?.imputedProperties?.description)}
52
52
  <p class="description">{page?.description || page?.imputedProperties.description}</p>
@@ -54,6 +54,6 @@
54
54
 
55
55
  {#if level < 2 && content}
56
56
  <div class="content">
57
- <Markdown props={{ ast, level, website }} />
57
+ <Markdown props={{ ast, level, website, format }} />
58
58
  </div>
59
59
  {/if}
@@ -37,7 +37,7 @@ export default async function mutateMarkdownAST(ast, cache) {
37
37
  delete node.children;
38
38
  } catch (error) {
39
39
  node.value = url;
40
- console.log(`Error on URL in content: ${url}`);
40
+ // console.log(`Error on URL in content: ${url}`);
41
41
  }
42
42
  } else {
43
43
  node.metadata = cache[node.value];
@@ -89,7 +89,7 @@ export default async function mutateMarkdownFrontmatter(frontmatter, cache) {
89
89
  input
90
90
  };
91
91
  } catch (e) {
92
- console.error(`Error on URL in frontmatter: ${frontmatter[key]}`);
92
+ // console.error(`Error on URL in frontmatter: ${frontmatter[key]}`);
93
93
  frontmatter[key] = {
94
94
  type: 'string',
95
95
  output: input,
@@ -103,6 +103,8 @@ async function readFolder(folderPath, parents, cache) {
103
103
 
104
104
  let files = (await fs.readdir(folderPath, { withFileTypes: true })).filter(filterFiles);
105
105
 
106
+ console.log(`filesfound:${files.length}`);
107
+
106
108
  const promises = files.map(async (file) => await readFile(file, parents, cache, folderPath));
107
109
 
108
110
  const folder = (await Promise.all(promises)).reduce((acc, obj) => ({ ...acc, ...obj }), {});
@@ -134,7 +136,8 @@ async function readFile(file, parents, cache, folderPath) {
134
136
 
135
137
  const { ast, frontmatter, imputedProperties } = await readMarkdownFile(filePath, cache);
136
138
  const loadTime = (performance.now() - startLoad).toFixed(2);
137
- console.log(`📄 ${shortPath} (${loadTime}ms)`);
139
+ // console.log(`📄 ${shortPath} (${loadTime}ms)`);
140
+ console.log('fileread');
138
141
  if (frontmatter.published == false) return;
139
142
  if (file.name === 'home.md' || file.name === 'settings.md') {
140
143
  const key = file.name === 'home.md' ? '$' : '_';
@@ -173,7 +176,7 @@ async function readFile(file, parents, cache, folderPath) {
173
176
  const folder = await readFolder(path.join(folderPath, file.name), url, cache);
174
177
 
175
178
  const loadTime = (performance.now() - startLoad).toFixed(2);
176
- console.log(`📁 ${shortPath} (${loadTime}ms)`);
179
+ // console.log(`📁 ${shortPath} (${loadTime}ms)`);
177
180
 
178
181
  if (!folder.hasOwnProperty('$')) {
179
182
  const $ = DefaultFile(url);
@@ -208,5 +211,7 @@ export default async function processMarkdownFiles(cache) {
208
211
  const [homeDir] = $home;
209
212
  const folder = await readFolder(homeDir, '', cache);
210
213
 
214
+ console.log('loaded');
215
+
211
216
  return { folder, finalCache: cache };
212
217
  }
@@ -22,15 +22,15 @@ async function checkFileExists(filePath, homeDir) {
22
22
 
23
23
  /** @type {import('./$types').PageLoad} */
24
24
  export async function load() {
25
- const startLoad = performance.now();
25
+ // const startLoad = performance.now();
26
26
  const now = Date.now();
27
27
  const contentCacheDuration = 60000; // Cache for 1 minute
28
28
  const initialURLCache = await loadCache($home[0]);
29
29
 
30
30
  const cssExists = await checkFileExists(normalize('/assets/styles.css'), $home[0]);
31
31
 
32
- if (cssExists) console.log('Found CSS file at /assets/styles.css');
33
- else console.log('No CSS file found as /assets/styles.css');
32
+ // if (cssExists) console.log('Found CSS file at /assets/styles.css');
33
+ // else console.log('No CSS file found as /assets/styles.css');
34
34
 
35
35
  const faviconExists = await checkFileExists(normalize('/assets/favicon.png'), $home[0]);
36
36
 
@@ -51,7 +51,7 @@ export async function load() {
51
51
  console.log('Using content cache');
52
52
  data = contentCache;
53
53
  } else {
54
- console.log('Not using content cache');
54
+ // console.log('Not using content cache');
55
55
  data = await processMarkdownFiles(initialURLCache);
56
56
  contentCache = data;
57
57
  contentCacheTime = now;
@@ -64,7 +64,7 @@ export async function load() {
64
64
  writeCache(finalCache, $home[0]);
65
65
  }
66
66
 
67
- console.log(`Load time: ${(performance.now() - startLoad).toFixed(2)} ms`);
67
+ // console.log(`Load time: ${(performance.now() - startLoad).toFixed(2)} ms`);
68
68
 
69
69
  const folderName = basename($home[0]);
70
70
 
@@ -42,8 +42,8 @@
42
42
  }
43
43
 
44
44
  const breadcrumbs = getBreadcrumbs().slice(1, -1).reverse();
45
- const breadcrumbSegment = breadcrumbs.length ? `${breadcrumbs.join(' - ')}` : '';
46
- return `${pageMetaTitle} - ${breadcrumbSegment} - ${siteTitle}`;
45
+ const breadcrumbSegment = breadcrumbs.length ? ` - ${breadcrumbs.join(' - ')} - ` : '';
46
+ return `${pageMetaTitle}${breadcrumbSegment}${siteTitle}`;
47
47
  }
48
48
 
49
49
  function getFavicon() {
@@ -98,7 +98,7 @@ export async function GET({}) {
98
98
  entry.push({
99
99
  content: [
100
100
  { _attr: { type: 'html' } },
101
- render(Page, { props: { page, level: 0, format: 'xml' } }).html
101
+ render(Page, { props: { page, level: 0, format: 'rss' } }).html
102
102
  ]
103
103
  });
104
104
 
package/svelte.config.js CHANGED
@@ -1,10 +1,15 @@
1
1
  import adapter from '@sveltejs/adapter-static';
2
2
  import path, { join } from 'path';
3
+ import mri from 'mri';
4
+
5
+ const args = mri(process.argv);
6
+
7
+ const isDev = args._.includes('dev');
3
8
 
4
9
  const demoDir = process.cwd() + '/content';
5
- const NPMRunDev = process.argv[2] === 'dev';
6
- const isBuild = process.argv[2] === 'build';
7
- const receivedHomePath = NPMRunDev || isBuild ? false : process.argv[2];
10
+ // const NPMRunDev = process.argv[2] === 'dev';
11
+ // const isBuild = process.argv[2] === 'build';
12
+ const receivedHomePath = isDev || args.build ? false : args.directory;
8
13
  const homeDir = receivedHomePath || demoDir;
9
14
  const relativePathToHome = path.relative(process.cwd(), homeDir);
10
15
 
package/vite.config.js CHANGED
@@ -2,11 +2,14 @@ import { sveltekit } from '@sveltejs/kit/vite';
2
2
  import { defineConfig } from 'vite';
3
3
  import path from 'path';
4
4
  import { readMarkdownFile, loadCache } from './src/lib/utilities/index';
5
+ import mri from 'mri';
6
+
7
+ const args = mri(process.argv);
5
8
 
6
9
  const demoDir = process.cwd() + '/content';
7
10
  const NPMRunDev = process.argv[2] === 'dev';
8
11
  const isBuild = process.argv[2] === 'build';
9
- const receivedHomePath = NPMRunDev || isBuild ? false : process.argv[2];
12
+ const receivedHomePath = NPMRunDev || isBuild ? false : args.directory;
10
13
 
11
14
  const homeDir = receivedHomePath || demoDir;
12
15
 
@@ -19,7 +22,6 @@ export default defineConfig({
19
22
  // Hot reload markdown
20
23
  name: 'markdown:watch',
21
24
  configureServer(server) {
22
- console.log(`Root directory: ${homeDir}`);
23
25
  server.watcher.add(homeDir);
24
26
  server.watcher.on('change', async (homePath, stats) => {
25
27
  if (homePath.endsWith('.md')) {