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 · 20 comments

Comments

Projects
None yet
@nicolinuxfr

nicolinuxfr commented Jun 13, 2015

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 from Option to use singular for taxonomies URL to Option to change taxonomies URL Jun 13, 2015

@hacdias

This comment has been minimized.

Show comment
Hide comment
@hacdias

hacdias Jun 28, 2015

Contributor

+1

Contributor

hacdias commented Jun 28, 2015

+1

1 similar comment
@gerswin

This comment has been minimized.

Show comment
Hide comment
@gerswin

gerswin commented Jul 17, 2015

+1

@Jos512

This comment has been minimized.

Show comment
Hide comment
@Jos512

Jos512 Oct 6, 2015

Great idea; +1!

Jos512 commented Oct 6, 2015

Great idea; +1!

@josenaves

This comment has been minimized.

Show comment
Hide comment
@josenaves

josenaves commented Dec 16, 2015

+1

@milosvvv

This comment has been minimized.

Show comment
Hide comment
@milosvvv

milosvvv Mar 2, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@marcojakob

marcojakob Apr 19, 2016

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.

marcojakob commented Apr 19, 2016

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

This comment has been minimized.

Show comment
Hide comment
@peterychuang

peterychuang May 8, 2016

Contributor

+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.

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

This comment has been minimized.

Show comment
Hide comment
@dekked

dekked 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?

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

This comment has been minimized.

Show comment
Hide comment
@peterychuang

peterychuang May 12, 2016

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.

Contributor

peterychuang commented May 12, 2016

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

This comment has been minimized.

Show comment
Hide comment
@dekked

dekked 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 :(

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

This comment has been minimized.

Show comment
Hide comment
@peterychuang

peterychuang May 13, 2016

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.

Contributor

peterychuang commented May 13, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@pmphillips

pmphillips May 23, 2016

+1 Really looking forward to this as well.

pmphillips commented May 23, 2016

+1 Really looking forward to this as well.

@sivaprasadreddy

This comment has been minimized.

Show comment
Hide comment
@sivaprasadreddy

sivaprasadreddy Jun 11, 2016

@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 commented Jun 11, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@sivaprasadreddy

sivaprasadreddy Jun 11, 2016

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.

sivaprasadreddy commented Jun 11, 2016

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

This comment has been minimized.

Show comment
Hide comment
@dekked

dekked Sep 15, 2016

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

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

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

This comment has been minimized.

Show comment
Hide comment
@jmcbee

jmcbee 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/.

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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Jan 15, 2017

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@denyskoch

denyskoch Jan 17, 2017

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

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

denyskoch commented Jan 17, 2017

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

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

This comment has been minimized.

Show comment
Hide comment
@denyskoch

denyskoch 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?

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

More reorganization to support Jekyll
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

More reorganization to support Jekyll
Hack to rename categories to blog/categories so that URLs
will continue to map properly.

See gohugoio/hugo#1208 (comment)
@charneykaye

This comment has been minimized.

Show comment
Hide comment
@charneykaye

charneykaye Jul 18, 2017

+1 in config.toml I want to

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

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

Handle Taxonomy permalinks
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

Handle Taxonomy permalinks
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 in #4061 Nov 7, 2017

bep added a commit that referenced this issue Nov 7, 2017

Handle Taxonomy permalinks
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.

bep added a commit that referenced this issue Nov 7, 2017

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