/
githubmirror
/
obsidian-importer
Обзор
Документация
Войти
/
githubmirror
/
obsidian-importer
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/base.ts
54 строки
2 KB
Steph Ango
Solve the suppressed findings instead of disabling them
05 авг 2026, 01:10
05 авг 2026, 01:10
3dd5a17
Код
Авторство
О чём код?
import { path } from './filesystem'; import { TFolder, TFile, BasesConfigFile, stringifyYaml, normalizePath, Vault } from 'obsidian'; /** * How an importer treats a source database's computed fields (formulas, rollups, * lookups, counts). * * 'static' writes the value the source last computed into each note. 'hybrid' * translates the expression into a Base formula where it can, so the values stay * live, and falls back to the static value where it cannot. */ export type FormulaImportStrategy = 'static' | 'hybrid'; /** * Creates a Base file in the specified folder. * * @param folder - The folder to create the Base file in * @param fileName - Name of the Base file (without .base extension) * @param options - Configuration for the Base file content * @param vault - Obsidian vault instance * @returns The created TFile * * @example * ```ts * await createBaseFile(folder, 'CSV import', { * filters: 'file.folder == "CSV import"', * views: [{ * type: 'table', * name: 'Table', * order: ['file.name', 'title', 'date', 'category'] * }] * }, this.app.vault); * ``` */ export async function createBaseFile( folder: TFolder, fileName: string, contents: BasesConfigFile, vault: Vault ): Promise<TFile> { const yamlContent = stringifyYaml(contents); const filePath = normalizePath(path.join(folder.path, fileName + '.base')); // Check if file already exists const existingFile = vault.getAbstractFileByPath(filePath); if (existingFile instanceof TFile) { // Update existing file await vault.modify(existingFile, yamlContent); return existingFile; } // Create new file return await vault.create(filePath, yamlContent); }