1
Fork 0
mirror of https://github.com/Steffo99/obsidian-file-index.git synced 2024-11-22 05:04:17 +00:00

Remove steffo- prefix

This commit is contained in:
Steffo 2023-11-17 14:46:34 +01:00
parent b477b8ae68
commit 1c7822a58b
Signed by: steffo
GPG key ID: 2A24051445686895
4 changed files with 25 additions and 25 deletions

View file

@ -2,7 +2,7 @@
## About ## About
This [Obsidian] plugin creates and keeps updated a `steffo-file-index.json` file at the root of your Vault, containing a list of all file paths and a map of all basenames to file paths. This [Obsidian] plugin creates and keeps updated a `file-index.json` file at the root of your Vault, containing a list of all file paths and a map of all basenames to file paths.
Useful to externally render Wikilinks with no knowledge of the file structure of the vault, for example in [Obsiview]. Useful to externally render Wikilinks with no knowledge of the file structure of the vault, for example in [Obsiview].
@ -25,7 +25,7 @@ Useful to externally render Wikilinks with no knowledge of the file structure of
## Ignore ## Ignore
Files can be excluded by the index by adding a `steffo-file-index-ignore.json` file at the root of your Vault, containing a JSON array of regular expressions that will prevent matching files from being added to the list: Files can be excluded by the index by adding a `file-index-ignore.json` file at the root of your Vault, containing a JSON array of regular expressions that will prevent matching files from being added to the list:
```json ```json
[ [

40
main.ts
View file

@ -1,46 +1,46 @@
import {Plugin, TFile, TFolder} from "obsidian" import {Plugin, TFile, TFolder} from "obsidian"
export interface SteffoFileIndex { export interface FileIndex {
basenames: {[basename: string]: string}, basenames: {[basename: string]: string},
paths: string[], paths: string[],
} }
export default class SteffoFileIndexPlugin extends Plugin { export default class FileIndexPlugin extends Plugin {
static FILE_IGNORE_PATH = "steffo-file-index-ignore.json" static FILE_IGNORE_PATH = "file-index-ignore.json"
ignoreRegExps: RegExp[] = [] ignoreRegExps: RegExp[] = []
async reloadIgnoreRegExps() { async reloadIgnoreRegExps() {
const ignoreFile = this.app.vault.getAbstractFileByPath(SteffoFileIndexPlugin.FILE_IGNORE_PATH) const ignoreFile = this.app.vault.getAbstractFileByPath(FileIndexPlugin.FILE_IGNORE_PATH)
if(ignoreFile === null) { if(ignoreFile === null) {
console.debug("[SteffoFileIndexPlugin] Ignore file does not exist, not ignoring anything:", SteffoFileIndexPlugin.FILE_IGNORE_PATH) console.debug("[FileIndexPlugin] Ignore file does not exist, not ignoring anything:", FileIndexPlugin.FILE_IGNORE_PATH)
this.ignoreRegExps = [] this.ignoreRegExps = []
} }
else if(ignoreFile instanceof TFolder) { else if(ignoreFile instanceof TFolder) {
console.debug("[SteffoFileIndexPlugin] Ignore file is actually a folder, not ignoring anything:", SteffoFileIndexPlugin.FILE_IGNORE_PATH) console.debug("[FileIndexPlugin] Ignore file is actually a folder, not ignoring anything:", FileIndexPlugin.FILE_IGNORE_PATH)
this.ignoreRegExps = [] this.ignoreRegExps = []
} }
else if(ignoreFile instanceof TFile) { else if(ignoreFile instanceof TFile) {
const ignoreJSON = await this.app.vault.cachedRead(ignoreFile) const ignoreJSON = await this.app.vault.cachedRead(ignoreFile)
const ignoreContents: string[] = JSON.parse(ignoreJSON) const ignoreContents: string[] = JSON.parse(ignoreJSON)
this.ignoreRegExps = ignoreContents.map((re) => new RegExp(re)) this.ignoreRegExps = ignoreContents.map((re) => new RegExp(re))
console.debug("[SteffoFileIndexPlugin] Determined ignore list to be:", this.ignoreRegExps) console.debug("[FileIndexPlugin] Determined ignore list to be:", this.ignoreRegExps)
} }
else { else {
console.error("[SteffoFileIndexPlugin] Ignore file is of an unknown type, not doing anything:", SteffoFileIndexPlugin.FILE_IGNORE_PATH) console.error("[FileIndexPlugin] Ignore file is of an unknown type, not doing anything:", FileIndexPlugin.FILE_IGNORE_PATH)
} }
} }
async reloadIgnoreRegExpsIfIgnoreFileChanged(file: TFile) { async reloadIgnoreRegExpsIfIgnoreFileChanged(file: TFile) {
if(file.path === SteffoFileIndexPlugin.FILE_IGNORE_PATH) { if(file.path === FileIndexPlugin.FILE_IGNORE_PATH) {
await this.reloadIgnoreRegExps() await this.reloadIgnoreRegExps()
} }
} }
static FILE_INDEX_PATH = "steffo-file-index.json" static FILE_INDEX_PATH = "file-index.json"
async recreateFileIndex() { async recreateFileIndex() {
const files = this.app.vault.getFiles() const files = this.app.vault.getFiles()
@ -64,32 +64,32 @@ export default class SteffoFileIndexPlugin extends Plugin {
const basename = file.basename.toLocaleLowerCase() const basename = file.basename.toLocaleLowerCase()
if(basenames.hasOwnProperty(basename)) { if(basenames.hasOwnProperty(basename)) {
console.warn("[SteffoFileIndexPlugin] Multiple files with the same basename detected:", basenames[basename], file.path) console.warn("[FileIndexPlugin] Multiple files with the same basename detected:", basenames[basename], file.path)
} }
basenames[basename] = file.path basenames[basename] = file.path
} }
paths.sort() paths.sort()
const index: SteffoFileIndex = {basenames, paths} const index: FileIndex = {basenames, paths}
console.debug("[SteffoFileIndexPlugin] Determined index to be:", index) console.debug("[FileIndexPlugin] Determined index to be:", index)
const indexContents = JSON.stringify(index, null, "\t") const indexContents = JSON.stringify(index, null, "\t")
const indexFile = this.app.vault.getAbstractFileByPath(SteffoFileIndexPlugin.FILE_INDEX_PATH) const indexFile = this.app.vault.getAbstractFileByPath(FileIndexPlugin.FILE_INDEX_PATH)
if(indexFile === null) { if(indexFile === null) {
console.debug("[SteffoFileIndexPlugin] File index does not exist, creating it right now at:", SteffoFileIndexPlugin.FILE_INDEX_PATH) console.debug("[FileIndexPlugin] File index does not exist, creating it right now at:", FileIndexPlugin.FILE_INDEX_PATH)
await this.app.vault.create(SteffoFileIndexPlugin.FILE_INDEX_PATH, indexContents) await this.app.vault.create(FileIndexPlugin.FILE_INDEX_PATH, indexContents)
} }
else if(indexFile instanceof TFolder) { else if(indexFile instanceof TFolder) {
console.debug("[SteffoFileIndexPlugin] Cannot create file index, as there's a folder at:", SteffoFileIndexPlugin.FILE_INDEX_PATH) console.debug("[FileIndexPlugin] Cannot create file index, as there's a folder at:", FileIndexPlugin.FILE_INDEX_PATH)
} }
else if(indexFile instanceof TFile) { else if(indexFile instanceof TFile) {
console.debug("[SteffoFileIndexPlugin] File index already exists, overwriting contents of:", SteffoFileIndexPlugin.FILE_INDEX_PATH) console.debug("[FileIndexPlugin] File index already exists, overwriting contents of:", FileIndexPlugin.FILE_INDEX_PATH)
await this.app.vault.modify(indexFile, indexContents) await this.app.vault.modify(indexFile, indexContents)
} }
else { else {
console.error("[SteffoFileIndexPlugin] File index is of an unknown type, not doing anything:", SteffoFileIndexPlugin.FILE_INDEX_PATH) console.error("[FileIndexPlugin] File index is of an unknown type, not doing anything:", FileIndexPlugin.FILE_INDEX_PATH)
} }
} }
@ -99,7 +99,7 @@ export default class SteffoFileIndexPlugin extends Plugin {
async onload() { async onload() {
this.addCommand({ this.addCommand({
id: 'steffo-file-index-recreate', id: 'recreate',
name: 'Force file index recreation', name: 'Force file index recreation',
callback: this.recreateFileIndex.bind(this) callback: this.recreateFileIndex.bind(this)
}) })

View file

@ -1,5 +1,5 @@
{ {
"id": "steffo-file-index", "id": "file-index",
"name": "File Index", "name": "File Index",
"version": "2.0.0", "version": "2.0.0",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "steffo-file-index", "name": "file-index",
"version": "2.0.0", "version": "3.0.0",
"description": "Obsidian plugin to create a metadata file about the files present in the Vault", "description": "Obsidian plugin to create a metadata file about the files present in the Vault",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {