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

feat: add gh_edit_collections_dir #1155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

hepheir
Copy link

@hepheir hepheir commented Feb 6, 2023

Hello everyone! I made this PR to enhance existing feature: "Edit this page on GitHub" link text on footer.

In this pr, gh_edit_collections_dir key is added on the _config.yml. Users will be able to configure gh_edit_collections_dir to customize url of the "Edit this page on GitHub".

Leaving this value empty will make the gh_edit feature behaves same as before, therefore no worries for backward compatibility :)

I believe that this feature will be useful for those who use nested repository to store documents in a seperated github repository, like I do:

image

Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

Thank you for submitting this PR @hepheir!

I want to make sure I understand your use case. It seems like from the code you've submitted, you want to prepend gh_edit_collections_dir to all pages, regardless of whether or not they're in a specific collection. Separately, you also are overriding site.collections_dir.

In this case, could you instead accomplish the same goal by changing site.gh_edit_source? It is unclear what the difference between that option and gh_edit_collections_dir is (if you also set collections_dir = nil).

@hepheir
Copy link
Author

hepheir commented Feb 16, 2023

Thanks for the comment @mattxwang :)

In my case, I have set collections_dir = docs since all the documents are located at docs/. Meanwhile docs/ is not just an ordinary directory but a git-submodule repository:

Therefore, I wanted the button "Edit this page on GitHub" to direct user to the submodule. This could be accomplished by customizing gh_edit_repository. But changing gh_edit_repository did not satisfy me since generated urls did not point pages correctly.

: The pages are located right under the root directory of the submodule. while site.collections_dir is causing the url to point to the wrong directory(docs/).

In this case, could you instead accomplish the same goal by changing site.gh_edit_source? It is unclear what the difference between that option and gh_edit_collections_dir is (if you also set collections_dir = nil).

That's a sharp point. I thought exactly the same thing that i could fix this by changing site.gh_edit_source.

And what i did was to set the value of it as .., expecting it to behaves like this:

- ...github.com/user/repository/tree/master/../docs/**/*
+ ...github.com/user/repository/tree/master/**/*

But what actually happened was:

- ...github.com/user/repository/tree/master/../docs/**/*
+ ...github.com/user/repository/tree/docs/**/*

I have come to the conclusion that the url in the front can be modified, but the url that follows cannot be modified.
So I ended up adding an option for gh_edit_collections_dir which was the only way to solve this problem while maintaining backward compatibility.

@mattxwang
Copy link
Member

Thank you for the clear explanation @hepheir, definitely helps me understand your use-case! I agree that this is something we should aim to support.

However, I'm a bit wary of polluting the global site.config namespace, and also want this solution to scale to multiple directories (my understanding is -- if you had two different collections, one in a submodule and one not, that this would break).

Let me suggest an alternative solution: instead, we can read metadata from site.collections; to sketch out an API, it would be something like:

collections:
  docs:
    gh_edit_collections_dir: '...' # your stuff goes here!

My hope is that this way, we can not add any more variables to the config space, and instead use what Jekyll has built in for us already.

(implicit here is whether this should prepend or replace site.collections_dir, etc.)

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants