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

Option to change taxonomies URL #1208

Closed
nicolinuxfr opened this issue Jun 13, 2015 · 24 comments · Fixed by #4061
Closed

Option to change taxonomies URL #1208

nicolinuxfr opened this issue Jun 13, 2015 · 24 comments · Fixed by #4061

Comments

@nicolinuxfr
Copy link

As discussed here on the forum, it would be nice to have the ability to change the default URLs generated by Hugo for taxonomies.

Right now, we only have plural form, like http://website.tld/tags/cat. An option could give instead http://website.tld/tag/catfor the same URL.

Maybe a good solution would be to let user decide what he wants in the URL. That way, we could choose the singular instead of plural, but also an other word completely (http://website.tld/pet/cat), or nothing at all (http://website.tld/cat).

EDIT : as described here, there's an easy way to have singular instead of plural. But we could have an option to change entirely the URL.

@nicolinuxfr nicolinuxfr changed the title Option to use singular for taxonomies URL Option to change taxonomies URL Jun 13, 2015
@hacdias
Copy link
Contributor

hacdias commented Jun 28, 2015

+1

1 similar comment
@gerswin
Copy link

gerswin commented Jul 17, 2015

+1

@Jos512
Copy link

Jos512 commented Oct 6, 2015

Great idea; +1!

@josenaves
Copy link

+1

@milosvvv
Copy link

milosvvv commented Mar 2, 2016

+1 would be useful for us using non-english languages, I've managed to translate everything except the "Tags" :(

@marcojakob
Copy link

This would also allow us to create taxonomy urls that are inside the same folder as a section:

  • /blog/tags/foo
  • /blog/tags/bar

This is the same URL scheme that Jekyll is using.

It is also discussed in create section taxonomies.

@peterychuang
Copy link
Contributor

peterychuang commented May 8, 2016

+1
That's about the only thing stopping me from switching from Jekyll to Hugo. Everything else works for me, or at least have some workarounds.

@dekked
Copy link

dekked commented May 8, 2016

Is this still not possible?

I want to create my main website and blog in the same Hugo site, with the contents of the blog all inside /blog. Therefore I want the tags and categories to be /blog/tags and /blog/categories, not just /tags. Anyone figured a workaround for this?

@peterychuang
Copy link
Contributor

When you define categories and tags in your config file, you have to declare the single and plural form of it as per the documentation:

taxonomies:
  tag: "tags"
  category: "categories"

Correct me if I'm wrong. I believe the taxonomies urls are formed by taking the plural, so it is possible to change the config into something like this:

taxonomies:
  tag: "hello"

and in the front matter of your page, instead of using "tags", you use "hello" to define the tags:

hello:
- tag1
- tag2

The path to the tag listing will become http://yoursite/hello/tag1

You can probably put any string in place of "tags" or "categories," but it cannot be empty.

@dekked
Copy link

dekked commented May 13, 2016

@peterychuang I could hack my way around this with your suggestion 😄

I wondered if using a string such as blog/tags for plural would work, and it turns out it does!

In the templates I had to change things like {{ with .Params.tags }} to {{ with (index .Params "blog/tags") }}, but I got the urls working as I wanted in the end!

So, to sum up:

In config.toml:

[taxonomies]
    tag = "blog/tags"
    category = "blog/categories"

In the front matter of any markdown post:

+++
"blog/categories" = ["One cat", "another cat"]
"blog/tags" = ["One tag", "Another tag"]
+++

I know the front matter looks a little weird, but no way around that :(

@peterychuang
Copy link
Contributor

@dekked Glad that it works out for you.

I figured out a not-so-pretty way to remove "categories" from the url. The downside of doing so are 1) pagination doesn't work, and 2) the original category pages at /categories/cat1 are still being generated.

Not an ideal solution, but works for me, for now.

@pmphillips
Copy link

+1 Really looking forward to this as well.

@sivaprasadreddy
Copy link

@dekked Your solution is almost what I wanted (blog/categories, blog/tags).

But I am unable to figure it out how to display all tags/categories at site level.

Currently I am doing it as follows:

{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
{{ $name | title }}
{{ end }}

How to pass "blog/tags" to .Site.Taxonomies?

@sivaprasadreddy
Copy link

One way I found to do it is:

{{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
{{ if eq $taxonomyname "blog/tags" }}
{{ range $key, $value := $taxonomy }}
{{ $key | title }}
{{ end }}
{{ end }}
{{ end }}

Not sure whether it is optimal way or not, but working.

@dekked
Copy link

dekked commented Sep 15, 2016

@sivaprasadreddy sorry for the late response. You can do this:

  {{ range $key, $value := index .Site.Taxonomies "blog/tags" -}}
  ...
  {{ end -}}

@jmcbee
Copy link

jmcbee commented Jan 15, 2017

Stumbled into this problem as well. When you have your posts in /blog/, but your blog tags are at /tag/foo/ instead of /blog/tag/foo/.

@bep
Copy link
Member

bep commented Jan 15, 2017

For a given taxonomy list, I'm pretty sure you can set the url in the taxonomy lists` frontmatter to whatever you want, but I guess that is not very practical if you want to change them all.

@denyskoch
Copy link

why not general purpose url rewrite configuration? something like this:

[urlRewrite]
"/categories/bla" = "/bla"
"/categories" = false
"/posts/(.*)" = "/$1"

@denyskoch
Copy link

denyskoch commented Jan 19, 2017

btw. neither content/categories/_index.md nor content/categories/cat1/_index.md using frontmatter url param. Title is used but not url and not slug.

looks like the switch-statement in https://github.com/spf13/hugo/blob/d6000a208c7687ca3a3efd6961ac941ce325e199/hugolib/page.go#L1413 is the source of this problem. If we remove it, we could define urls to taxonomies/tag in permalinks like

[permalinks]
categories = "/:filename:/"

or am I wrong?

sit added a commit to sit/Hugo-Octopress that referenced this issue Apr 29, 2017
Hack to rename categories to blog/categories so that URLs
will continue to map properly.

See gohugoio/hugo#1208 (comment)
sit added a commit to sit/Hugo-Octopress that referenced this issue Apr 29, 2017
Hack to rename categories to blog/categories so that URLs
will continue to map properly.

See gohugoio/hugo#1208 (comment)
@charneykaye
Copy link

charneykaye commented Jul 18, 2017

+1 in config.toml I want to

[permalinks]
  post = "/:slug/"
  page = "/:slug/"
  category = "/:slug/"

betaveros added a commit to betaveros/hugo that referenced this issue Nov 7, 2017
Return the correct virtual Section for Taxonomy and TaxonomyTerm.
Restrict permalink expansion to only Pages and Taxonomies, but then
actually use expanded permalinks even for non-Pages.

Fixes gohugoio#1208.
betaveros added a commit to betaveros/hugo that referenced this issue Nov 7, 2017
Return the correct virtual Section for Taxonomy and TaxonomyTerm.
Restrict permalink expansion to only Pages and Taxonomies, but then
actually use expanded permalinks even for non-Pages.

Fixes gohugoio#1208.
@bep bep added this to the v0.31 milestone Nov 7, 2017
@bep bep added the Enhancement label Nov 7, 2017
@bep bep closed this as completed in #4061 Nov 7, 2017
bep pushed a commit that referenced this issue Nov 7, 2017
Return the correct virtual Section for Taxonomy and TaxonomyTerm.
Restrict permalink expansion to only Pages and Taxonomies, but then
actually use expanded permalinks even for non-Pages.

Fixes #1208.
@ghost
Copy link

ghost commented Apr 30, 2020

+1 in config.toml I want to

[permalinks]
  post = "/:slug/"
  page = "/:slug/"
  category = "/:slug/"

Did this work?

@ghost
Copy link

ghost commented Apr 30, 2020

btw. neither content/categories/_index.md nor content/categories/cat1/_index.md using frontmatter url param. Title is used but not url and not slug.

looks like the switch-statement in https://github.com/spf13/hugo/blob/d6000a208c7687ca3a3efd6961ac941ce325e199/hugolib/page.go#L1413 is the source of this problem. If we remove it, we could define urls to taxonomies/tag in permalinks like

[permalinks]
categories = "/:filename:/"

or am I wrong?

Did we get a resolution on this? I'm a good enough golang programmer to trust myself to not introduce bugs.

bep added a commit that referenced this issue Oct 6, 2020
9abd3043a Add docs for shimming JS libraries
6a1c8dcd7 Update sitemap-template.md (#1245)
37c397332 Update frontends.md
a0f86f6df Update configuration.md
bb00cb2c1 Update page-bundles.md
773212de6 Restructure and simplify
fcba7dddf Some minor clarifications of weight sorting
759b967fc Update configuration-markup.md
56708f0b7 module import path remove slash at end
59f4f4acd Doc: Fix typo in hugo command
faacf2e97 Clarify pagination documentation (#1208)
d8eb60887 netlify: Bump to 0.75.1
8cedf6231 Merge branch 'temp751'
188e2bf56 releaser: Add release notes to /docs for release of 0.75.1
c96d4b7a3 Update index.md
1a9d192f7 Update index.md
32731b916 Update index.md
a5bfa0c9a Restore the ... home page
b6850bf96 Release 0.75.0
d6e5e624f releaser: Add release notes to /docs for release of 0.75.0
8cd6b4f47 typo: already -> already
2cb2b22bb Merge commit '534ae9c57a902aea9ed6e62390dec11fa74b7122'
e3525de23 docs: Regen docs helper
fd746dd83 docs: Regenerate CLI docs
e20127980 Add "hugo mod npm pack"
8e82c7ce1 markup/highlight: Add support to linkable line anchors on Chroma
21e94911b markup/asciidocext: Fix AsciiDoc TOC with code
50b8dace5 modules: Add noVendor to module config
d05b541fe modules: Make ignoreVendor a glob pattern
c946082e7 docs: Update replaceRE func
149054341 docs: Update replace func
d917567df docs: Update merge function
f1e093c92 docs: Regen CLI docs
c7bac967d docs: Regen docs helper
7a38f7a45 Merge commit '7d7771b673e5949f554515a2c236b23192c765c8'
1a5a7263a markup/asciidoc: Add support for .TableOfContents

git-subtree-dir: docs
git-subtree-split: 9abd3043a9214b390e8cc148f4588bf630620851
@saefulrahman
Copy link

+1 in config.toml I want to

[permalinks]
  post = "/:slug/"
  page = "/:slug/"
  category = "/:slug/"

Did this work?

Its work, just change the custom permalink in config.toml.

[taxonomies]
  category = "category"
  tag = "tag"

[permalinks]
   category = "/blog/category/:slug/"
   tags = "/blog/tags/:slug/"

In the front matter of any markdown post:

+++
category:
    - Hugo
tag:
    - Go
+++

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.