Enveloppe / obsidian-enveloppe

Enveloppe helps you to publish your notes on a GitHub repository from your Obsidian Vault, for free!
https://enveloppe.github.io/
Apache License 2.0
613 stars 38 forks source link

[Bug]: frontmatter repeat #302

Closed miaogaolin closed 7 months ago

miaogaolin commented 7 months ago

Issue validation

Command used

Upload single current active note

Plugin version

6.14.1

Describe the bug

When replacing Properties with regular expressions, the frontmatter content will be repeated.

Replacement options: Run replacement before the other plugin

How to reproduce ?

my own example:

---
share: true
cover.image: "4444"
---

regular expressions:

Value to replace: `/cover\.image/`
Replacement: `cover:\n    image`

Replacement options: Run replacement before the other plugin

Result:

---
share: true
cover.image: "4444"
---
---
share: true
cover:
    image: "4444"
---

Minimal Reproducible Example

-

Configuration

{
  "github": {
    "branch": "main",
    "automaticallyMergePR": false,
    "dryRun": {
      "enable": false,
      "folderName": "github-publisher-test"
    },
    "tokenPath": "%configDir%/plugins/%pluginID%/env",
    "api": {
      "tiersForApi": "Github Free/Pro/Team (default)",
      "hostname": ""
    },
    "workflow": {
      "commitMessage": "[PUBLISHER] Merge",
      "name": ""
    },
    "verifiedRepo": true
  },
  "upload": {
    "behavior": "yaml",
    "defaultName": "content/posts",
    "rootFolder": "content",
    "yamlFolderKey": "dir",
    "frontmatterTitle": {
      "enable": false,
      "key": "title"
    },
    "replaceTitle": [],
    "replacePath": [],
    "autoclean": {
      "enable": false,
      "excluded": []
    },
    "folderNote": {
      "enable": false,
      "rename": "index.md",
      "addTitle": {
        "enable": false,
        "key": "title"
      }
    },
    "metadataExtractorPath": ""
  },
  "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [
      {
        "entry": "/\\]\\(([^)\\.]+)\\.md/",
        "replace": "]({{< relref \"$1.md\" >}}",
        "flags": "",
        "after": true,
        "inCodeBlocks": false
      },
      {
        "entry": "/cover\\.image/",
        "replace": "cover:\\n    image",
        "flags": "",
        "after": false
      },
      {
        "entry": "/\\]\\(([^/]+?)\\.(png|jpg|jpeg|webp|gif)/",
        "replace": "](/images/$1.$2",
        "flags": "",
        "after": true
      },
      {
        "entry": "/\\!\\[\\[([^/]+?)\\.(png|jpg|jpeg|webp|gif)\\|(\\d+)(x(\\d+))?\\]\\]/",
        "replace": "{{< figure src=\"/images/$1.$2\"  width=\"$3\" height=\"$5\">}}",
        "flags": "",
        "after": false
      },
      {
        "entry": "/\\!\\[\\[([^/]+?)\\.(png|jpg|jpeg|webp|gif)\\|([^\\|]*?)(\\|(\\d+)(x(\\d+))?)?\\]\\]/",
        "replace": "{{< figure src=\"/images/$1.$2\" caption=\"$3\" width=\"$5\" height=\"$7\">}}",
        "flags": "",
        "after": false
      }
    ],
    "tags": {
      "inline": true,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": false,
      "unshared": false,
      "wiki": true,
      "slugify": "lower"
    }
  },
  "embed": {
    "attachments": true,
    "overrideAttachments": [],
    "keySendFile": [],
    "notes": false,
    "folder": "static/images",
    "convertEmbedToLinks": "keep",
    "charConvert": "->",
    "forcePushAttachments": [],
    "useObsidianFolder": false
  }
}

Relevant log output

No response

OS

Windows

Anything else?

No response

Obsidian information

v1.5.3
miaogaolin commented 7 months ago

I'm really sorry. It was fine after I restarted obsidian

Mara-Li commented 7 months ago

Please continue the discussion here @tobiasvl Could you please send me a minimal file to reproduce?

tobiasvl commented 7 months ago

@Lisandra-dev Yes, I reproduced it just with this minimal file:

---
title: Foo
published: false
synced: true
jekyll_tags:
  - foo
---
Foo

It's obviously the rewriting of "jekyll_tags" to "tags" that is causing it, as it didn't happen before I added it, but then it happened when I did - and in one front matter it says "jekyll_tags", while the other says "tags" (which is what I want). I've tried with and without regex (it doesn't need regex, but I tested it all the same).

My settings:

{
  "github": {
    "branch": "main",
    "automaticallyMergePR": true,
    "dryRun": {
      "enable": false,
      "folderName": "github-publisher"
    },
    "tokenPath": "%configDir%/plugins/%pluginID%/env",
    "api": {
      "tiersForApi": "Github Free/Pro/Team (default)",
      "hostname": ""
    },
    "workflow": {
      "commitMessage": "[PUBLISHER] Merge",
      "name": ""
    },
    "verifiedRepo": true
  },
  "upload": {
    "behavior": "obsidian",
    "defaultName": "",
    "rootFolder": "",
    "yamlFolderKey": "",
    "frontmatterTitle": {
      "enable": false,
      "key": "title"
    },
    "replaceTitle": [
      {
        "regex": "",
        "replacement": "",
        "type": "title"
      }
    ],
    "replacePath": [
      {
        "regex": "/blog",
        "replacement": "",
        "type": "path"
      }
    ],
    "autoclean": {
      "enable": false,
      "excluded": []
    },
    "folderNote": {
      "enable": false,
      "rename": "index.md",
      "addTitle": {
        "enable": false,
        "key": "title"
      }
    },
    "metadataExtractorPath": ""
  },
  "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [
      {
        "entry": "jekyll_title:",
        "replace": "title:",
        "after": false
      }
    ],
    "tags": {
      "inline": false,
      "exclude": [],
      "fields": [
        "jekyll_tags"
      ]
    },
    "links": {
      "internal": true,
      "unshared": false,
      "wiki": true,
      "slugify": "disable"
    }
  },
  "embed": {
    "attachments": true,
    "overrideAttachments": [],
    "keySendFile": [],
    "notes": false,
    "folder": "../assets/images",
    "convertEmbedToLinks": "keep",
    "charConvert": "->"
  }
}
tobiasvl commented 7 months ago

I don't know TS, but the problem might be that findAndReplaceText() is first called with text, then later text and frontmatter is concatenated, and then findAndReplaceText() is called again on that combined text? https://github.com/ObsidianPublisher/obsidian-github-publisher/blob/7487831596c037727e7b308fa33ad6695c7f0ffa/src/conversion/convert_text.ts#L190-L210

Mara-Li commented 7 months ago

processYaml is used if you use some settings to edit the frontmatter, like the auto adding title and tags. But maybe it create some conflict when you edit it. It's pretty strange, as I can't reproduce it.

The only advice I can send you is to uninstall Obsidian Publisher and reinstall it.

tobiasvl commented 7 months ago

Ah. Yes, that put me on the right track (the processYaml, not the reinstallation). If you keep this issue open a while longer I'll see if I can fix it.

Mara-Li commented 7 months ago

Yeah, no problem^^

Mara-Li commented 7 months ago

Could you please try the 6.14.2 ?

tobiasvl commented 7 months ago

@Lisandra-dev Yep, that seems to work! Along the lines of what I thought the issue was. Thank you!