mirror of
https://github.com/al0cam/AutoMover.git
synced 2026-07-22 05:41:25 +00:00
Merge pull request #10 from al0cam/fix-tagfrontmatter
Fix tagfrontmatter
This commit is contained in:
commit
eaa35a746b
5 changed files with 11 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import type { MovingRule } from "Models/MovingRule";
|
||||
import { ProjectRule } from "Models/ProjectRule";
|
||||
import type { TagCache, TFile } from "obsidian";
|
||||
import type { TFile } from "obsidian";
|
||||
|
||||
class RuleMatcherUtil {
|
||||
private static instance: RuleMatcherUtil;
|
||||
|
|
@ -64,7 +64,7 @@ class RuleMatcherUtil {
|
|||
* @param rules
|
||||
* @returns MovingRule | null
|
||||
*/
|
||||
public getMatchingRuleByTag(tags: TagCache[], rules: MovingRule[]): MovingRule | null {
|
||||
public getMatchingRuleByTag(tags: string[], rules: MovingRule[]): MovingRule | null {
|
||||
for (const rule of rules) {
|
||||
if (rule.regex == null || rule.regex === "") {
|
||||
console.error("Tag Rule does not have a regex: ", rule);
|
||||
|
|
@ -81,7 +81,7 @@ class RuleMatcherUtil {
|
|||
|
||||
const regex = this.getCompiledRegex(rule.regex);
|
||||
for (const tag of tags) {
|
||||
if (regex.test(tag.tag)) {
|
||||
if (regex.test(tag)) {
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
|
|
@ -104,11 +104,11 @@ class RuleMatcherUtil {
|
|||
return matches;
|
||||
}
|
||||
|
||||
public getGroupMatchesForTags(tags: TagCache[], rule: MovingRule): RegExpMatchArray | null {
|
||||
public getGroupMatchesForTags(tags: string[], rule: MovingRule): RegExpMatchArray | null {
|
||||
const regex = this.getCompiledRegex(rule.regex);
|
||||
// console.log("Compiled regex: ", regex);
|
||||
for (const tag of tags) {
|
||||
const matches = tag.tag.match(regex);
|
||||
const matches = tag.match(regex);
|
||||
if (matches) {
|
||||
return matches;
|
||||
}
|
||||
|
|
|
|||
4
main.ts
4
main.ts
|
|
@ -137,7 +137,9 @@ export default class AutoMoverPlugin extends obsidian.Plugin {
|
|||
* @returns true if the file was moved, false otherwise
|
||||
*/
|
||||
matchAndMoveByTag(file: obsidian.TFile): boolean {
|
||||
const tags = this.app.metadataCache.getFileCache(file)?.tags;
|
||||
const cache = this.app.metadataCache.getFileCache(file);
|
||||
if (cache == null) return false;
|
||||
const tags = obsidian.getAllTags(cache);
|
||||
if (tags == null || tags.length === 0) return false;
|
||||
|
||||
const tagRule = ruleMatcherUtil.getMatchingRuleByTag(tags, this.settings.tagRules);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "auto-mover",
|
||||
"name": "AutoMover",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Move files and notes with specified names into their designated folders according to rules you define.",
|
||||
"author": "Al0cam",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "AutoMover",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"description": "AutoMover: Move files and notes with specified names into their designated folders according to rules you define.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"1.0.7": "0.15.0"
|
||||
"1.0.8": "0.15.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue