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

[Plugin][FR]: Remove .md extension from generated links #176

Closed
1 task done
quinn-p-mchugh opened this issue Jul 3, 2023 · 16 comments
Closed
1 task done

[Plugin][FR]: Remove .md extension from generated links #176

quinn-p-mchugh opened this issue Jul 3, 2023 · 16 comments
Assignees
Labels
💎 Obsidian Github Publisher Related to the plugin ✨ Enhancement New feature or request

Comments

@quinn-p-mchugh
Copy link

quinn-p-mchugh commented Jul 3, 2023

Issue validation

  • I checked the issue to prevent duplicate

Is your feature related to a problem ?

I recently confirmed that Docusaurus does not support relative markdown linking between blog and doc pages.

This means that the relative markdown links ([link](../../docs/.md#) ) generated by the Obsidian GitHub Publisher plugin do not work for links between pages in the blog section and the docs section any Docusaurus website. This might be fixed in the future, but one of the lead developer's notes that this would require a significant change to how links are routed in Docusaurus.

However, using standard URL links (without the .md extension) work just fine.

For example:
If I provide a link in a blog post like [link](../../docs/relevant-doc-page.md#), the link does not work.

whereas...

When I remove the .md extension ([link](../../docs/relevant-doc-page)), the link routes successfully.

What solution do you want to see ?

As a workaround, I'd like an option to remove the .md extension from all wikilinks that are converted to relative markdown links, so these links work properly on websites built with Docusaurus.

So instead of: [link](../../docs/relative-doc-page.md#)

It should be: [link](../../docs/relative-doc-page)

This could be a matter of including the file extension in any user-specified regular expressions in the Apply edit on the folder path or filename (automatically) setting, allowing users to remove the .md file extension by specifying .md under Value to replace and nothing for the Replacement value.

Describe the alternative you've considered

Other solutions might look like:

  • Providing a boolean option (i.e. Omit .md file extension?) in the Content's conversion section to omit the .md file extension for any [[Wikilinks]] that are converted to [MDlinks](links).

OS

Windows

Anything else?

I think enabling the ability to modify file extensions (in addition to filename and folder path) in the Apply edit on the folder path or filename (automatically) setting would be the most flexible solution. However, this may or may not cause issues in the event that users' existing regex replace settings happen to match the .md file extension.

Plugin version

6.2.5

Obsidian version & debug log

N/A
@Mara-Li
Copy link
Member

Mara-Li commented Jul 3, 2023

Real question: did you try to use the regex replacement of contents to remove the .MD extension?

Probably something with \((.*)\.md(.*)\)($1$2)

See https://regex101.com/r/2xMqDG/1

You can remove the # part with juste using ($1) as replacement.

@Mara-Li Mara-Li changed the title [Plugin][FR]: [Plugin][FR]: Remove .md extension from generated links Jul 3, 2023
@quinn-p-mchugh
Copy link
Author

quinn-p-mchugh commented Jul 3, 2023

Hi @Lisandra-dev,

Great question - this may very well be a case of user error!

I'll give the above suggestion a try, but given that use of backslashes yields an error (see #172), I'll need to wait until the new release to begin testing.

Thanks for your prompt response! Very much appreciate the help here.

@quinn-p-mchugh
Copy link
Author

quinn-p-mchugh commented Jul 3, 2023

FWIW, I've confirmed that the following (non-regex) replacement does not remove the .md extension.

image

Also: thank you for filling in the issue title - I neglected to do this by mistake. My apologies.

@Mara-Li
Copy link
Member

Mara-Li commented Jul 4, 2023

As I said in my first post, you need to set the regex in the content remplacement. Not in the path remplacement.

@quinn-p-mchugh
Copy link
Author

quinn-p-mchugh commented Jul 4, 2023

Hi @Lisandra-dev,

Ah, thank you - I'll read more carefully next time.

Hmmm... it seems the following settings in the Text replacer setting do not remove the .md extension from links.
image

I've verified convertWikiLinks function is called before the findAndReplaceText function, so no issues there.

I might have to do some debugging on my end to see what might be going awry.

In any case, here's my settings and test content, in case anything jumps out at you.

Settings

{
  "github": {
    "branch": "main",
    "automaticallyMergePR": true,
    "tokenPath": "%configDir%/plugins/%pluginID%/env",
    "api": {
      "tiersForApi": "Github Free/Pro/Team (default)",
      "hostname": ""
    },
    "workflow": {
      "commitMessage": "[Obsidian GitHub Publisher] Merge",
      "name": ""
    },
    "verifiedRepo": true
  },
  "upload": {
    "behavior": "yaml",
    "defaultName": "docs",
    "rootFolder": "",
    "yamlFolderKey": "publish-path",
    "frontmatterTitle": {
      "enable": true,
      "key": "publish-filename"
    },
    "replaceTitle": [
      {
        "regex": "/\\s+/",
        "replacement": "-",
        "type": "title"
      }
    ],
    "replacePath": [],
    "autoclean": {
      "enable": false,
      "excluded": []
    },
    "folderNote": {
      "enable": false,
      "rename": "index.md"
    },
    "metadataExtractorPath": ""
  },
  "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [
      {
        "entry": "/\\.md/",
        "replace": "//",
        "after": false
      },
      {
        "entry": ".md",
        "replace": "",
        "after": false
      },
      {
        "entry": "/\\((.*)\\.md(.*)\\)/",
        "replace": "/$1$2/",
        "after": false
      },
      {
        "entry": "/\\.md/",
        "replace": "",
        "after": false
      }
    ],
    "tags": {
      "inline": false,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": true,
      "unshared": false,
      "wiki": true,
      "slugify": true
    }
  },
  "embed": {
    "attachments": true,
    "keySendFile": [],
    "notes": true,
    "folder": ""
  }
}

Test file contents (In Obsidian):

test-blog-post.md

---
publish: true
publish-path: blog/2022
publish-filename: 
---
[[test-docs-post]]

test-docs-post.md

---
publish: true
publish-path: docs
publish-filename: 
---
[[test-blog-post]]

Result (In GitHub)

test-blog-post.md

---
publish: true
publish-path: blog/2022
publish-filename: 
---
[test-docs-post](../../docs/test-docs-post.md#)

test-docs-post.md

---
publish: true
publish-path: docs
publish-filename: 
---
[test-blog-post](../blog/2022/test-blog-post.md#)

@Mara-Li
Copy link
Member

Mara-Li commented Jul 4, 2023

Change the arrow to down :)

@quinn-p-mchugh
Copy link
Author

quinn-p-mchugh commented Jul 5, 2023

Ah, shoot. Thank you @Lisandra-dev! Changing the arrow to down resolved my issue.

I've provided the full resolution below for anyone with similar inquiries.

Solution (to remove .md from markdown links)

  • Open plugin settings
  • Go to Content's conversion section.
  • Verify [[Wikilinks]] to [MDlinks](links) settings is enabled.
  • Edit Text replacer setting.
  • Add a new entry using the plus button.
  • Under Value to Replace, enter the following regex: /(\[.*?\]\(.*?).md(.*?\))/ (see here for explanation)
  • Under Replacement, enter $1$2
  • Click the arrow and make sure it is pointed downward.
  • Click Save
  • Reload plugin, if necessary.

The markdown links generated by Obsidian GitHub publisher should now omit the .md extension while maintaining any anchor links (link#my-heading). This should resolve cross-section (blog --> docs) linking issues with Docusarus.

@abbychau
Copy link

image

It seems it the links in dataview are not being replaced.
can anyone verify?

@Mara-Li
Copy link
Member

Mara-Li commented Sep 30, 2023

What do you mean by the links in dataview ?

@abbychau
Copy link

Tables in dataview have a link called File, which is a link.

@Mara-Li
Copy link
Member

Mara-Li commented Sep 30, 2023

image

No problem on my side :/

Here my settings tested:

 "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [
      {
        "entry": "/(\\[.*?\\]\\(.*?).md(.*?\\))/",
        "replace": "$1$2",
        "flags": "",
        "after": true
      }
    ],
    "tags": {
      "inline": false,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": true,
      "unshared": true,
      "wiki": true,
      "slugify": false
    }

@abbychau
Copy link

mine is this:

  "conversion": {
    "hardbreak": true,
    "dataview": true,
    "censorText": [
      {
        "entry": "/(\\[.*?\\]\\(.*?).md(.*?\\))/",
        "replace": "$1$2",
        "flags": "",
        "after": true
      }
    ],
    "tags": {
      "inline": false,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": true,
      "unshared": false,
      "wiki": true,
      "slugify": true
    }
  },

in your screenshot, it seems that only the first row of the table was replaced but other links are still with .md is that right?

@Mara-Li
Copy link
Member

Mara-Li commented Sep 30, 2023

Oh, yeah, I think you need to use g in the regex. Like that: /(\[.*?\]\(.*?).md(.*?\))/g

@abbychau
Copy link

I have added g at the end. but no matter if it is added or unadded. .md is still not being replaced.

@Mara-Li
Copy link
Member

Mara-Li commented Sep 30, 2023

image
Works on my side :/

@abbychau
Copy link

abbychau commented Oct 1, 2023

I rebuilt my repo and it is working now. thanks.
(the plugin was not pushing changes after editing at all.

@Mara-Li Mara-Li added the ✨ Enhancement New feature or request label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Obsidian Github Publisher Related to the plugin ✨ Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants