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

Custom link handler #38

Merged
merged 18 commits into from
May 12, 2022
Merged

Conversation

jmbuhr
Copy link
Contributor

@jmbuhr jmbuhr commented May 11, 2022

Based on the discussion in #10

This adds the ability to pass a user-defined lua function to internally transform the path of a link.
Where internally means that the link will be displayed and written in the document un-transformed but it's transformed version will be used for file-creation and navigation.

This is helpful for navigating e.g. a folder of files created by https://logseq.com/

Note: In logseq one can choose the way dates for journal entries are displayed. For example, if the option YYYY-MM-DD is choosed this config works:

    perspective = {
        priority = 'root',
        fallback = 'current',
        root_tell = ".git"
    },
    prefix = {
        evaluate = false,
        string = "./"
    },
    links = {
        style = 'wiki',
        implicit_extension = nil,
        transform = function(input)
            if input:match('%d%d%d%d%-%d%d%-%d%d') then
                return('journals/'..input:gsub("%-","_"))
            else
                return('pages/'..input)
            end
        end
    },

It can now succesfullly open pages in pages, even those created by logseq for zotero entries, which logseq puts as pages/@..., as well as journal pages in journal.

@jmbuhr jmbuhr changed the base branch from dev to main May 11, 2022 20:58
@jmbuhr
Copy link
Contributor Author

jmbuhr commented May 11, 2022

I rebased it onto your main branch :)

@jakewvincent
Copy link
Owner

jakewvincent commented May 11, 2022

Thanks @jmbuhr! Looking forward to testing this out later today :)

@jakewvincent jakewvincent self-requested a review May 11, 2022 21:12
@jakewvincent jakewvincent added the enhancement New feature or request label May 11, 2022
Copy link
Owner

@jakewvincent jakewvincent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jmbuhr, this is an elegant solution :)

@jakewvincent
Copy link
Owner

Just merged this into dev, which I'll merge into main soon when I'm sure the other recent updates are ready :)

@jakewvincent
Copy link
Owner

Just added an explicit transformation option to complement this feature! The old prefix config option will now be provided under transform_explicit.

@jakewvincent jakewvincent merged commit 830a0f9 into jakewvincent:main May 12, 2022
@jmbuhr jmbuhr deleted the custom-link-handler branch May 12, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants