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

Change "post/" to "blog/" #356

Closed
kescobo opened this issue Oct 26, 2017 · 17 comments
Closed

Change "post/" to "blog/" #356

kescobo opened this issue Oct 26, 2017 · 17 comments

Comments

@kescobo
Copy link

kescobo commented Oct 26, 2017

I'd like to use the Posts widget, but change its name (and url) to "blog" instead. Is there a way to make this work?

I tried simply changing the folder path to blog/ instead of post/, but this broke it, and I started to try using the custom widget but realized I'd lose all of the functionality. I'd be grateful to be pointed along the right path.

@gcushen
Copy link
Collaborator

gcushen commented Oct 26, 2017

Refer to permalinks in the documentation.

@gcushen
Copy link
Collaborator

gcushen commented Oct 26, 2017

You can try something like adding the following near the top of your config.toml (before the [params] section):

[permalinks]
    post = "/blog/:slug"

@kescobo
Copy link
Author

kescobo commented Oct 26, 2017

Thanks for the quick response! Sorry I wasn't more clear in the issue. Yes, I've got the permalinks option set to "/blog/:year/:month/:slug", and that works great. The urls for all the posts themselves are fine. However:

  1. the list of posts is at http://nequals.me/post/ (I'd like it to be at http://nequals.me/blog/)
  2. the top menu item still says Posts (I'd like that to be Blog)
  3. the homepage link is http://nequals.me/#posts (I'd like that to be http://nequals.me/#blog)

@gcushen
Copy link
Collaborator

gcushen commented Oct 26, 2017

  1. Remove the [permalinks] config that you added since I discovered that Hugo doesn't yet support a smart way to change the URL for sections/archives (see Override section url gohugoio/hugo#3354). Rename post folder to blog. You'll need to delete the example posts (except _index.md) as they reference the post folder, which will cause errors.
  2. In config.toml, scroll to bottom of file and change the Posts link to:
[[menu.main]]
  name = "Blog"
  url = "#blog"
  weight = 3
  1. To change the widget link, simply rename the widget to blog.md
  2. Also, you can edit the title from Posts to Blog in your new blog archive at blog/_index.md and in your new blog widget home/blog.md.

@jagd
Copy link
Contributor

jagd commented Oct 26, 2017

I did the renaming in my private fork since very beginning when I switched to this template, by renaming the related files and modifying some htmls listed in git grep -i post.

Never had any problem with git merge in the last period.

Also don't forget the 404 page.

@gcushen
Copy link
Collaborator

gcushen commented Oct 26, 2017

Note that the permalink method of adding the following just above [params] section of config

[permalinks]
    post = "/blog/:slug"

can work with archive pages too if you add aliases = ["/blog/"] to your post/_index.md.

I didn't mention it earlier as it will redirect /blog/ archive page to /post/ rather than rename it, so it's not ideal - but may be useful to someone.

@kescobo
Copy link
Author

kescobo commented Oct 27, 2017

  1. Remove the [permalinks] config that you added since I discovered that Hugo doesn't yet support a smart way to change the URL for sections/archives (see Override section url gohugoio/hugo#3354). Rename post folder to blog. You'll need to delete the example posts (except _index.md) as they reference the post folder, which will cause errors.
  2. In config.toml, scroll to bottom of file and change the Posts link to:
    [[menu.main]]
    name = "Blog"
    url = "#blog"
    weight = 3
  3. To change the widget link, simply rename the widget to blog.md
  4. Also, you can edit the title from Posts to Blog in your new blog archive at blog/_index.md and in your new blog widget home/blog.md.
  1. Done and done
  2. Done
  3. Done
  4. Done and done

Doing only this gave me the error when I tried to run hugo:

ERROR 2017/10/26 16:44:59 Error while rendering "home": template: theme/index.html:1:3: executing "theme/index.html" at <partial "widget_page...>: error calling partial: template: theme/partials/widget_page.html:23:9: executing "theme/partials/widget_page.html" at <partial $widget $par...>: error calling partial: Partial "widgets/blog.html" not found

Changing post.html to blog.html as well as a bunch of references in there from post->blog got rid of the error, and now the menu item and http://www.nequals.me#blogare there, but the widget doesn't actually display the blog posts. I must be missing one final piece...

@gcushen
Copy link
Collaborator

gcushen commented Oct 27, 2017

post.html does not need to be changed to blog.html, and index.html/widget_page.html do not need to be altered. I meant change home/post.md to home/blog.md. The widget variable in your home/blog.md should not be changed - it should remain as widget = "posts".

Also, you'll want to specify type = "post" in the frontmatter of your posts in order for them to be fully recognized as blog post type of content.

@kescobo
Copy link
Author

kescobo commented Oct 28, 2017

Ahh, my mistake. (Also, incidentally, thanks for being so responsive, sorry getting this right is taking such effort). I've reverted the stuff in the theme, and changed back to widget = "posts". Also added type="post" to all posts.

I think it's close. The one outstanding thing is that the link from the widget "more posts" links to '/post/'. But when I build and push the site, there's nothing at /post/ (I get a 404 error). All of the links in the widget are going to the right place, and those pages are built. (/blog/ is still with all of the posts, though formatted slightly differently than /post/ was when it was working).

If I remove the alias=["/blog/"] from _index.md, the behavior seems the same. (eg "More posts" link goes to /post/, but there's nothing there. /blog/* links are all working). Note, all of the above is without [permalinks] set in my config.toml file. Changing that back to post = "/blog/:year/:month/:slug"), doesn't change anything, but including blog = "/blog/:year/:month/:slug" seems to work, though the "More posts" link is still broken.

@gcushen
Copy link
Collaborator

gcushen commented Oct 28, 2017

To attempt to fix your More Posts link, you can add aliases = ["/post/"] to your blog/_index.md front-matter. Alternatively, the hard-coded <a href="{{ "/post/" | relLangURL }}"> can be changed to <a href="{{ "/blog/" | relLangURL }}"> in the posts.html file which you found earlier.

Hopefully, Hugo team will implement gohugoio/hugo#3354 soon and then this URL customization process will be much simpler.

@kescobo
Copy link
Author

kescobo commented Oct 29, 2017

The alias thing worked - awesome! Thanks a bunch.

Incidentally, the styling of the /blog/ page isn't the same as the default /post/ page (the post titles are blue and slightly smaller), but this doesn't bother me over much.

@gcushen
Copy link
Collaborator

gcushen commented Oct 29, 2017

Ideally, you would be able to specify type = "post" in blog/_index.md so that it is recognized as your new post archive page. However, there is currently a bug in Hugo which prevents type working on _index.md archive pages (see gohugoio/hugo#3005).

You can attempt to work around this by copying themes/academic/layouts/section/post.html to layouts/section/blog.html, relative to the root of your site and creating the layouts/section/ folders if necessary. (Note: if you update the theme in the future, you may need to perform this process again so that your version of the file gets any available update applied to it.)

@kescobo
Copy link
Author

kescobo commented Oct 29, 2017

Ideally, you would be able to specify type = "post" in blog/_index.md so that it is recognized as your new post archive page.

Yeah, I actually did try this and noticed it didn't work. I'll avoid messing around in the theme so as not to mess with future updates. The functionality I have now is great - thanks for making such a great theme!

@kescobo kescobo closed this as completed Oct 29, 2017
the-redback added a commit to the-redback/the-redback.github.io that referenced this issue Jan 12, 2019
the-redback added a commit to the-redback/the-redback.github.io that referenced this issue Jan 12, 2019
the-redback added a commit to the-redback/the-redback.github.io that referenced this issue Feb 10, 2019
the-redback added a commit to the-redback/the-redback.github.io that referenced this issue Mar 6, 2019
the-redback added a commit to the-redback/the-redback.github.io that referenced this issue Mar 6, 2019
the-redback added a commit to the-redback/the-redback.github.io that referenced this issue Nov 9, 2019
@MarcKaufmann
Copy link

It seems that the upstream enhancement that you referred to is working, yet when I add type: "post" in blog/_index.md, the blog page still has different styling from what the posts page was. Should it be working and I need to reconfigure, or is it still not working and I misread the thread?

@mtlmacedo
Copy link

Just for record:
I had the same issue, and opted to simply rename "content/posts" to "content/blog" and created the symbolic link "content/posts".
In that solution, both "website.com/posts/..." and "website.com/blog/..." works fine without any issues

@ETOgaosion
Copy link

Is it a tradition that blogs must be put together in post?

@wrobelda
Copy link

wrobelda commented May 2, 2024

I have content/posts folder renamed to content/journal on my end, with _index.md as

+++
title = "Journal"
name = "Journal"
draft = false
+++

and the following menu entry in config file:

  [[menu.main]]
  identifier = "journal"
  name = "Journal"
  pageRef = "/journal"
  weight = 10

And I don't see any side effects. Keeping posts and with permalink settings worked seemingly fine, except but I could not get breadcrumbs to work properly.

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

No branches or pull requests

7 participants