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

How can I have different "Edit this page" URL for each page #150

Closed
undergroundwires opened this issue Feb 22, 2020 · 9 comments
Closed

Comments

@undergroundwires
Copy link
Contributor

Background

  • I have two repositories consisting of ".md" files.
  • I created a script that clones them, remaps file structure (see Collapsing options in menu file #149) and adds hugo-book metadata. In the end the script creates ready-to-go content/ and static/ folders.

What I'm trying to achieve

  • Edit this page URL for each page.

Problem

  • Master files exist in two different repositories.
  • Folder & file name structure in those repositories does not match the file structure of the website.
  • So I can't use BookRepo and BookEditPath
@alex-shpak
Copy link
Owner

Hi!
I would say there is no easy solution.

What you can try:

  1. Add url (or path) of original file to frontmatter of each .md file. For example:
---
BookEditPath: your/path/here
---
  1. Overwrite /layouts/partials/docs/footer.html. You don't need to fork theme, you can override that specific file in your website. And make use of .Params.BookEditPath instead of .Site.Params.BookEditPath and change this line accordingly

And then if you plan to migrate fully to hugo - remove this change after.

@alex-shpak
Copy link
Owner

alex-shpak commented Feb 22, 2020

Also.

I thought for some time to add nested menu support. Maybe that would solve your problem.

There are 2 menus: menu: before and menu: after in theme. they are native hugo menus and page can be attached to it via frontmatter. They rendered before and after side menu accordingly.

About

@alex-shpak
Copy link
Owner

So I just added it to master. But then realised that it would not solve your problem with collapsing menu 😞

So overwriting template I guess is the option.

@undergroundwires
Copy link
Contributor Author

@alex-shpak thanks for your fast responses and supporting this project. It's awesome that you do that.

Menu nesting is not a direct solution but it's cool that hugo-book supports it now 👍

I really don't want to patch my local copy of the theme. I simply build another customized site generator on top of hugo and hugo-book where I iterate each markdown file and add edit link on them.

I can try to look at it & send a PR if you think hugo-book should natively support something like PageEditUrl that overrides BookEditPath and BookRepo if it has any value.

@alex-shpak
Copy link
Owner

Well, you don't need patch theme itself but overwrite template with Hugo.
Something like:

yoursite/
  themes/book/... <- theme files
  layouts/partials/docs/footer.html <- your custom changes

In this case you need only to watch theme changes for that specific file.
A bit ugly idea: if you edit files automatically you can disable theme's edit button and generate link to edit in the end of the file.

As for adding PageEditUrl I think it is quite specific case, so I don't want to add it to theme, you know, keep it simple. Sorry.

@alex-shpak
Copy link
Owner

@undergroundwires
Copy link
Contributor Author

Thanks for all explanation, I learnt a lot today.

I loved the solution with inject templates 👌. It seems to be the cleanest way, and makes the theme very extensible 💪.

I decided to have the buttons on the top, right before the page content. I see that there's an inject template for footer.html but not page-header.html or something similar. I tried to override header.html but I see that it's a mobile-only partial.

I got it working by adding shortcodes in markdown files using a script, a dirty workaround but does the work, and I don't need to watch for the theme changes =)

image

@alex-shpak
Copy link
Owner

Cool 👍 I also added content-before and content-after inject templates.

@undergroundwires
Copy link
Contributor Author

content-before has solved the extra customization for this special case in an elegant way.

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

No branches or pull requests

2 participants