markform-cli 1.0.1 → 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
@@ -23,6 +23,11 @@ npm install -g markform-cli
23
23
  markform ./my-notes -o ./output
24
24
  ```
25
25
 
26
+ If it doesn't work (mainly on windows), use:
27
+ ```bash
28
+ npx markform-cli ./test -o ./output
29
+ ```
30
+
26
31
  **Watch mode** — auto-rebuilds and live-reloads the browser on file changes:
27
32
  ```bash
28
33
  markform ./my-notes -o ./output --watch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markform-cli",
3
- "version": "1.0.1",
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": {
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>