initial-commit

This commit is contained in:
nicwands
2026-02-24 13:32:15 -05:00
commit fe12109209
5 changed files with 1070 additions and 0 deletions

65
src/FileSystemAdapter.js Normal file
View File

@@ -0,0 +1,65 @@
import { BaseNotesAdapter } from 'takerofnotes-plugin-sdk'
import matter from 'gray-matter'
import fs from 'fs/promises'
import path from 'path'
export default class FileSystemAdapter extends BaseNotesAdapter {
constructor(config) {
super()
for (const field in config) {
this[field] = config[field]
}
}
async init() {
await fs.mkdir(this.notesDir, { recursive: true })
}
async getAll() {
const files = await fs.readdir(this.notesDir)
const notes = []
for (const file of files) {
if (!file.endsWith('.md')) continue
const fullPath = path.join(this.notesDir, file)
const raw = await fs.readFile(fullPath, 'utf8')
const parsed = matter(raw)
notes.push({
...parsed.data,
content: parsed.content,
})
}
return notes
}
async create(note) {
await this._write(note)
}
async update(note) {
await this._write(note)
}
async delete(id) {
const filePath = path.join(this.notesDir, `${id}.md`)
await fs.unlink(filePath)
}
async _write(note) {
const filePath = path.join(this.notesDir, `${note.id}.md`)
const fileContent = matter.stringify(note.content, {
id: note.id,
title: note.title,
category: note.category ?? null,
createdAt: note.createdAt,
updatedAt: note.updatedAt,
})
await fs.writeFile(filePath, fileContent, 'utf8')
}
}

24
src/index.js Normal file
View File

@@ -0,0 +1,24 @@
import path from 'path'
import { app } from 'electron'
import FileSystemAdapter from './FileSystemAdapter'
import { definePlugin } from 'takerofnotes-plugin-sdk'
export default definePlugin({
id: 'filesystem',
name: 'Filesystem',
description: 'Store notes as markdown files on your local filesystem',
version: '1.0.0',
apiVersion: '0.1.0',
configSchema: [
{
key: 'notesDir',
label: 'Notes Directory',
type: 'directory',
default: path.join(app.getPath('userData'), 'notes'),
required: true,
},
],
createAdapter(config) {
return new FileSystemAdapter(config)
},
})