MCPcopy
hub / github.com/danielmiessler/Fabric / createNoteStore

Function createNoteStore

web/src/lib/store/note-store.ts:11–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9}
10
11function createNoteStore() {
12 const { subscribe, set, update } = writable<NoteState>({
13 content: '',
14 lastSaved: null,
15 isDirty: false
16 });
17
18 const createFrontmatter = (content: string): Frontmatter => {
19 const now = new Date();
20 const dateStr = now.toISOString();
21 const title = `Note ${now.toLocaleString()}`;
22 const cleanContent = content
23 .replace(/[#*`_]/g, '')
24 .replace(/\s+/g, ' ')
25 .trim();
26
27 return {
28 title,
29 aliases: [''],
30 description: cleanContent.slice(0, 150) + (cleanContent.length > 150 ? '...' : ''),
31 date: dateStr,
32 tags: ['inbox', 'note'],
33 updated: dateStr,
34 author: 'User',
35 };
36 };
37
38 const generateUniqueFilename = () => {
39 const now = new Date();
40 const date = now.toISOString().split('T')[0];
41 const time = now.toISOString().split('T')[1]
42 .replace(/:/g, '-')
43 .split('.')[0];
44 return `${date}-${time}.md`;
45 };
46
47 const saveToFile = async (content: string) => {
48 if (!browser) return;
49
50 const filename = generateUniqueFilename();
51 const frontmatter = createFrontmatter(content);
52 const fileContent = `---
53title: ${frontmatter.title}
54aliases: [${(frontmatter.aliases || []).map(alias => `"${alias}"`).join(', ')}]
55description: ${frontmatter.description}
56date: ${frontmatter.date}
57tags: [${(frontmatter.tags || []).map(tag => `"${tag}"`).join(', ')}]
58updated: ${frontmatter.updated}
59author: ${frontmatter.author}
60---
61
62${content}`;
63
64 const response = await fetch('/notes', {
65 method: 'POST',
66 headers: {
67 'Content-Type': 'application/json',
68 },

Callers 1

note-store.tsFile · 0.85

Calls 2

saveToFileFunction · 0.70
getFunction · 0.50

Tested by

no test coverage detected