markform-cli 1.0.0 → 1.1.1

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
@@ -1,4 +1,4 @@
1
- ![Markdown Banner](https://github.com/aryan-madan/Markform/blob/main/images/Markform%20%7C%20Banner.png?raw=true)
1
+ ![Markdown Banner](https://github.com/aryan-madan/Markform/blob/main/images/Markform%20|%20Devlog%202%20.png)
2
2
 
3
3
  Turn any folder of Markdown files into a beautiful, searchable static site — in one command.
4
4
  ```bash
@@ -9,6 +9,13 @@ I saw on reddit that people had folders of markdown files that needed to be sort
9
9
 
10
10
  ---
11
11
 
12
+ ## ⛏ Installation
13
+ ```bash
14
+ npm install -g markform-cli
15
+ ```
16
+
17
+ ---
18
+
12
19
  ## (ˆᗜˆ ) Usage
13
20
 
14
21
  **Build your site:**
@@ -16,6 +23,11 @@ I saw on reddit that people had folders of markdown files that needed to be sort
16
23
  markform ./my-notes -o ./output
17
24
  ```
18
25
 
26
+ If it doesn't work (mainly on windows), use:
27
+ ```bash
28
+ npx markform-cli ./test -o ./output
29
+ ```
30
+
19
31
  **Watch mode** — auto-rebuilds and live-reloads the browser on file changes:
20
32
  ```bash
21
33
  markform ./my-notes -o ./output --watch
@@ -23,7 +35,6 @@ markform ./my-notes -o ./output --watch
23
35
 
24
36
  ---
25
37
 
26
-
27
38
  ## (≖_≖ ) Options
28
39
 
29
40
  | Flag | Default | Description |
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "markform-cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Turn any folder of Markdown files into a beautiful, searchable static site.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
7
- "markform": "src/index.js"
7
+ "markform": "./src/index.js"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
package/src/build.js CHANGED
@@ -104,7 +104,15 @@ function getMdFiles(dir) {
104
104
 
105
105
  async function buildSearchIndex(mdFiles, inputDir, outputDir) {
106
106
  const index = mdFiles.map((filePath) => {
107
- const content = fs.readFileSync(filePath, 'utf-8');
107
+ const raw = fs.readFileSync(filePath, 'utf-8');
108
+ const content = raw
109
+ .replace(/#{1,6}\s/g, '') // headings
110
+ .replace(/\*\*|__|\*|_/g, '') // bold/italic
111
+ .replace(/`{1,3}[^`]*`{1,3}/g, '') // code
112
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // links
113
+ .replace(/^\s*[-*+]\s/gm, '') // list items
114
+ .replace(/\n+/g, ' ') // newlines
115
+ .trim();
108
116
  const relativePath = path.relative(inputDir, filePath);
109
117
  const href = relativePath.replace(/\.md$/, '.html');
110
118
  const title = path.basename(filePath, '.md').replace(/-/g, ' ');
package/test/hello.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # Hello World
2
2
 
3
- This is my first note.
3
+ This is my first note.
@@ -227,16 +227,33 @@
227
227
  .then(data => {
228
228
  fuse = new Fuse(data, {
229
229
  keys: ['title', 'content'],
230
- threshold: 0.4,
230
+ threshold: 0.1,
231
+ includeScore: true,
232
+ ignoreLocation: true,
233
+ minMatchCharLength: 3,
231
234
  });
232
235
  });
233
236
 
237
+ function highlight(text, query) {
238
+ if (!query) return text;
239
+ const regex = new RegExp(`(${query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
240
+ return text.replace(regex, '<mark style="background:#f9e2af;color:#1e1e2e;border-radius:3px;padding:0 2px;">$1</mark>');
241
+ }
242
+
243
+ function getSnippet(content, query) {
244
+ const idx = content.toLowerCase().indexOf(query.toLowerCase());
245
+ if (idx === -1) return content.slice(0, 100) + '...';
246
+ const start = Math.max(0, idx - 40);
247
+ const end = Math.min(content.length, idx + 80);
248
+ return (start > 0 ? '...' : '') + content.slice(start, end) + (end < content.length ? '...' : '');
249
+ }
250
+
234
251
  document.getElementById('search').addEventListener('input', function () {
235
252
  const query = this.value.trim();
236
253
  const navList = document.getElementById('nav-list');
237
254
  const results = document.getElementById('search-results');
238
255
 
239
- if (!query || !fuse) {
256
+ if (!query || !fuse || query.length < 2) {
240
257
  navList.style.display = '';
241
258
  results.style.display = 'none';
242
259
  results.innerHTML = '';
@@ -247,13 +264,17 @@
247
264
  navList.style.display = 'none';
248
265
  results.style.display = '';
249
266
  results.innerHTML = matches.length
250
- ? matches.map(m =>
251
- `<li style="margin-bottom:0.6rem">
252
- <a href="/${m.item.href}" style="color:#a6adc8;text-decoration:none;font-size:0.95rem;text-transform:capitalize;">
253
- ${m.item.title}
254
- </a>
255
- </li>`
256
- ).join('')
267
+ ? matches.map(m => {
268
+ const snippet = getSnippet(m.item.content, query);
269
+ return `<li style="margin-bottom:1rem">
270
+ <a href="/${m.item.href}" style="color:#cdd6f4;text-decoration:none;font-size:0.95rem;text-transform:capitalize;font-weight:600;">
271
+ ${highlight(m.item.title, query)}
272
+ </a>
273
+ <p style="color:#6c7086;font-size:0.8rem;margin-top:0.25rem;line-height:1.4;">
274
+ ${highlight(snippet, query)}
275
+ </p>
276
+ </li>`;
277
+ }).join('')
257
278
  : `<li style="color:#6c7086;font-size:0.9rem">No results found.</li>`;
258
279
  });
259
280
  </script>