1
Fork 0
mirror of https://github.com/Steffo99/obsidian-file-index.git synced 2024-11-24 22:14:21 +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
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].
@ -25,7 +25,7 @@ Useful to externally render Wikilinks with no knowledge of the file structure of
## 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
[

40
main.ts
View file

@ -1,46 +1,46 @@
import {Plugin, TFile, TFolder} from "obsidian"
export interface SteffoFileIndex {
export interface FileIndex {
basenames: {[basename: string]: string},
paths: string[],
}
export default class SteffoFileIndexPlugin extends Plugin {
static FILE_IGNORE_PATH = "steffo-file-index-ignore.json"
export default class FileIndexPlugin extends Plugin {
static FILE_IGNORE_PATH = "file-index-ignore.json"
ignoreRegExps: RegExp[] = []
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) {
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 = []
}
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 = []
}
else if(ignoreFile instanceof TFile) {
const ignoreJSON = await this.app.vault.cachedRead(ignoreFile)
const ignoreContents: string[] = JSON.parse(ignoreJSON)
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 {
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) {
if(file.path === SteffoFileIndexPlugin.FILE_IGNORE_PATH) {
if(file.path === FileIndexPlugin.FILE_IGNORE_PATH) {
await this.reloadIgnoreRegExps()
}
}
static FILE_INDEX_PATH = "steffo-file-index.json"
static FILE_INDEX_PATH = "file-index.json"
async recreateFileIndex() {
const files = this.app.vault.getFiles()
@ -64,32 +64,32 @@ export default class SteffoFileIndexPlugin extends Plugin {
const basename = file.basename.toLocaleLowerCase()
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
}
paths.sort()
const index: SteffoFileIndex = {basenames, paths}
console.debug("[SteffoFileIndexPlugin] Determined index to be:", index)
const index: FileIndex = {basenames, paths}
console.debug("[FileIndexPlugin] Determined index to be:", index)
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) {
console.debug("[SteffoFileIndexPlugin] File index does not exist, creating it right now at:", SteffoFileIndexPlugin.FILE_INDEX_PATH)
await this.app.vault.create(SteffoFileIndexPlugin.FILE_INDEX_PATH, indexContents)
console.debug("[FileIndexPlugin] File index does not exist, creating it right now at:", FileIndexPlugin.FILE_INDEX_PATH)
await this.app.vault.create(FileIndexPlugin.FILE_INDEX_PATH, indexContents)
}
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) {
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)
}
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() {
this.addCommand({
id: 'steffo-file-index-recreate',
id: 'recreate',
name: 'Force file index recreation',
callback: this.recreateFileIndex.bind(this)
})

View file

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

View file

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