Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: frontmatter repeat #302

Closed
3 tasks done
miaogaolin opened this issue Feb 5, 2024 · 9 comments
Closed
3 tasks done

[Bug]: frontmatter repeat #302

miaogaolin opened this issue Feb 5, 2024 · 9 comments
Assignees
Labels
🐛 Bug Something isn't working

Comments

@miaogaolin
Copy link

Issue validation

  • I checked the issue to prevent duplicate
  • I checked my configurations files and the documentation
  • My issue concern doesn't concern the Mkdocs template

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 miaogaolin added the 🐛 Bug Something isn't working label Feb 5, 2024
@miaogaolin
Copy link
Author

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

@Mara-Li Mara-Li reopened this Feb 6, 2024
@Mara-Li
Copy link
Member

Mara-Li commented Feb 6, 2024

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

@tobiasvl
Copy link

tobiasvl commented Feb 6, 2024

@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
Copy link

tobiasvl commented Feb 6, 2024

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
Copy link
Member

Mara-Li commented Feb 6, 2024

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
Copy link

tobiasvl commented Feb 6, 2024

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
Copy link
Member

Mara-Li commented Feb 6, 2024

Yeah, no problem^^

Mara-Li added a commit that referenced this issue Feb 6, 2024
see #302
Issue caused by censoring: by not founding the original frontmatter, because it use the frontmatter from cache and not the version censored
It stick the two frontmatter together, because it doesn't found the original.
Fixed by using the parsing YAML before the censoring
@Mara-Li
Copy link
Member

Mara-Li commented Feb 6, 2024

Could you please try the 6.14.2 ?

@tobiasvl
Copy link

tobiasvl commented Feb 6, 2024

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

@Mara-Li Mara-Li closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants