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

Categories in the path are ignored #2633

Merged
merged 2 commits into from Jul 27, 2014
Merged

Conversation

@redox
Copy link
Contributor

@redox redox commented Jul 24, 2014

When using subdirs to reflect categories, the underlying categories attribute was not set. I've added a new unit test and updated some others.

… attribute was not set
@parkr
Copy link
Member

@parkr parkr commented Jul 26, 2014

What are we missing? This shouldn't be necessary.

self.categories = dir.downcase.split('/').reject { |x| x.empty? }

@redox
Copy link
Contributor Author

@redox redox commented Jul 26, 2014

Not so sure because regarding the MATCHER regexp, it seems expected that the name will contain the categories. Guru review appreciated :)

    def initialize(site, source, dir, name)
      @site = site
      @dir = dir
      @base = self.containing_dir(source, dir)
      @name = name

      p name
      p dir
      self.categories = dir.downcase.split('/').reject { |x| x.empty? }
      self.process(name)
"troubleshooting/2014-7-24-why-is-the-number-of-returned-pages-limited-to-100.md"
""
@ivantsepp
Copy link
Contributor

@ivantsepp ivantsepp commented Jul 26, 2014

I think the way to have categories in your path is something like this:
troubleshooting/_posts/2014-7-24-why-is-the-number-of-returned-pages-limited-to-100.md
instead of
_posts/troubleshooting/2014-7-24-why-is-the-number-of-returned-pages-limited-to-100.md

This PR will allow for the second url to work which I think is more intuitive than the first one.

@@ -159,6 +159,8 @@ def <=>(other)
# Returns nothing.
def process(name)
m, cats, date, slug, ext = *name.match(MATCHER)
self.categories ||= []
self.categories += (cats || '').split('/')

This comment has been minimized.

@parkr

parkr Jul 26, 2014
Member

We should probably .map(&:downcase)

This comment has been minimized.

@redox

redox Jul 26, 2014
Author Contributor

Good catch @parkr, thank you.

parkr added a commit that referenced this pull request Jul 27, 2014
@parkr parkr merged commit 18c033d into jekyll:master Jul 27, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
parkr added a commit that referenced this pull request Jul 27, 2014
@redox redox deleted the redox:read_categories_from_path branch Jul 27, 2014
@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Aug 4, 2014

This change broke all my permalinks. I used subfolders in _posts to sort a large volume of posts arbitrarily. Now all of a sudden my posts have different URLs. Easy to fix, but jekyll really should show some love to URLs before making changes that will break them potentially. (IE "Warning: Subfolders in Posts will become categories by v.X")

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Aug 4, 2014

Actually it wasn't an easy change because changing from - permalink: pretty to -permalink: /:year/:month/:day/:title/ breaks all my page urls. See #2691

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Aug 5, 2014

As far as I can tell this change decreases functionality. I used to be able to have categories like this:

Create folder and put a _posts folder inside of it:

./category/anothercategory/_posts/

(in addition to just putting the category in the front-matter)

I used to be able to sort sort posts in that _post folder arbitrarily (for example by month, which program I used to generate the post etc...) and it was great! I could still have the full functionality of categories when using a folder above a _posts folder, or choose to not use them at all by just using the ./_posts folder with a ton of arbitrarily sorted posts with one off categories in the front-matter.

Now I literally can't do that and it sucks. And since the permalinks option does not seem to be working right, I can't fix this through a configuration option.

This feature of treating _post sub folders as a category should at the very least be:

A) Optional
B) Disabled by default

as it breaks existing sites, makes it impossible to sort post files inside of _post folders, and we already have a directory level shortcut to using categories by having extra _post files inside other folders in addition to the normal way of categorizing things with fron-matter.

@parkr
Copy link
Member

@parkr parkr commented Aug 5, 2014

Now I literally can't do that and it sucks

Because you're seeing categories in your URL's now?

This PR fixed a bug (if you look at the code, it was meant to use those subfolders inside _posts as categories, and people had complained about how it didn't do that before. Are you saying they remove the other categories?

We can't make these optional. My only thought is to either turn on or turn off all folder categories. The front matter categories would then overwrite any categories from the file path.

I'm sorry this broke your site, but you were exploiting a bug in Jekyll, not a feature. 😄

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Aug 5, 2014

@parkr What you are calling a bug has been a functionality of of Jekyll that I have used since August 2013, and I don't remember when this wasn't the case. So far I am able to test this functionality back to jekyll 0.7.0 from August 24, 2010! Still trying to see how far back it actually goes. Prose.io assumed this as well. Most hits regarding the topic note that _posts subfolders are a method for internally sorting posts inside of a _posts folder, but are flattened on generation and do not affect post metadata in any way.

We already have the ability to assign categories all posts in specific _posts folders, and most of the requests for category subfolders in _posts seem to come from people who are not fully aware of of the ./category/_posts functionality which is primarily a documentation issue. Having hundreds of post files inside of a single _posts folder that you do not wish to assign categories to is terrible to work with.

If anything this, at least externally, appears as a design decision (rather than a bug) which leaves me with a few questions/comments:

a) When did this "bug" appear?
b) When was the decision made to use _post subfolders as categories? (The same time the decision was made to make parent folders to _posts categories?) Was this documented anywhere? An issue perhaps?
c) This is duplicating the functionality that the _posts's parent folder already provides for a shortcut to categories. Shouldn't valuable _posts sub directory namespace information that was once ignored be reserved for something else like tags or at least made optional? (IE ./category/another-category/_posts/tag/another-tag/YYYY-MM-DD-postname.md Tags never hurt any slugs before 🐌 ).
d) I always understood that the whole philosophy of of the _posts folder was that any proper post file gets the slug from its filename:

Each post’s filename contains the publishing date and slug (what shows up in the URL) that the final HTML file should have. blogging like a hacker

This strays from that behavior in a pretty big way. What does @mojombo think of the change? Ignoring edge cases, the genius of the category folder above the _posts folder is that the post directory structure was generated inside that very category folder.

e) Before we had sortable post files that had no effect on post category. Now we don't and any regeneration on gh-pages where this update is mandatory and often unexpected unless you stay up on Jekyll news, breaks permalinks which is a faux pas as we can all agree. For sites that have lots of posts, this really sucks. If this was truly a bug, then it was certainly a useful one. Would you prefer I open a separate issue discussing the use of _posts subfolder behavior?

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Aug 6, 2014

I just noticed that the current documentation notes the extent of categories assigned to posts by directory pretty clearly here:
http://jekyllrb.com/docs/variables/#page-variables

Categories are derived from the directory structure above the _posts directory...These can also be specified in the YAML Front Matter.

Note, it says nothing about the use of subdirectories.

I would like to propose a revert of these changes until we can find a way assign subfolder information to posts in a way that is less disruptive and preferably optional or at least more flexible.

@parkr
Copy link
Member

@parkr parkr commented Aug 6, 2014

You're totally right. Can you whip up a PR to reverse this? Please leave the unit tests, but modify them so they expect no categories where we don't expect them. I'll add it to the 2.2.1 release.

We should have caught this with failing tests somewhere, but it seems we didn't add this as a test case before.

The docs you mention were written by TPW back before the 1.0 release: 17bb13a

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Aug 6, 2014

Sure. I can start that. I will start a new issue to discuss how attributing metadata to posts from _posts subdirs could work in a more compatible way, possibly through an option.

I'm going to rack my brain and jekyll sites for random 'tricks' that may be under documented so that we can nail these things down and get them documented better.

Also Apologies for the walls of text and excitement and thank you for all the other awesome changes in Jekyll lately! Your doing great work :)

Also noticed the acknowledgment of _posts subdirectories in the templates docs:

If you organize your posts in subdirectories, you need to include subdirectory path to the post:
{% post_url /subdir/2010-07-21-name-of-post %}

@bodokaiser
Copy link

@bodokaiser bodokaiser commented Oct 28, 2014

What is the state of this issue. Will support for subdirectories be added later?

@parkr
Copy link
Member

@parkr parkr commented Oct 28, 2014

What is the state of this issue. Will support for subdirectories be added later?

No. See #2705. The subdirectories are read but the categories will not be consumed. This is a historical, somewhat by-accident feature and will not be changed.

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Oct 29, 2014

@bodokaiser @parkr were you open to a PR allowing for sub dirs to assign meta data to posts as long is it didn't break the current behavior?

@SimplGy
Copy link

@SimplGy SimplGy commented May 2, 2015

@bcomnes, and others who find this a little unclear:

This folder structure creates a category:

/unicorns/_posts/2015-05-01-the-prettiest-one.md

This does not create a category, and it does not change the permalink:

/_posts/2015/2015-05-01-the-prettiest-one.md
@danijar
Copy link

@danijar danijar commented Oct 8, 2016

@bcomnes Did you find a way to use subdirs as categories without breaking existing behavior?

I would like to have quite a few categories. But there are also other top-level folders, for example holding statically hosted files. So it becomes confusing which directories is are categories and which are not.

@bodokaiser
Copy link

@bodokaiser bodokaiser commented Oct 9, 2016

No, not really but it has been a while since I tried

Am 09.10.2016 um 00:26 schrieb Danijar Hafner notifications@github.com:

@bcomnes Did you find a way to use subdirs as categories without breaking existing behavior?

I would like to have quite a few categories. But there are also other top-level folders, for example holding statically hosted files. So it becomes confusing which directories is are categories and which are not.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@jekyll jekyll locked and limited conversation to collaborators Jun 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants