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

Define behavior for is_post / posts #323

Closed
epage opened this issue Nov 2, 2017 · 4 comments
Closed

Define behavior for is_post / posts #323

epage opened this issue Nov 2, 2017 · 4 comments
Assignees
Milestone

Comments

@epage
Copy link
Member

epage commented Nov 2, 2017

Goals

  • Make rss / jsonfeed paths available to theme (RFC Reusable themes #301) / layout
  • Able to iterate on sorted posts for indexes
  • Can have title/description distinct from non-blog posts
  • Can be reused for collections
    • dedicated title, description, feed information, indexable
  • Minimal complication for non-collection use case
  • Minimal layout / theme complication

Use cases

  • A page that is an index of posts
    • ditto for collections
  • A post snippet that is a menu of posts
    • ditto for collections
    • Particularly a generic one
  • A post snippet that links to the RSS
    • ditto for collectons
    • Particularly a generic one
  • A page snippet that links to the posts RSS
    • ditto for a collection's RSS

Proposal

  • page.collection: Slug of the collection
  • collections.
    • title
    • description
    • rss_permalink
    • jsonfeed_permalink
    • pages

Use case solutions

Use cases

  • A page that is an index of posts: {% for post in collections.posts.pages %}
    • ditto for collections: {% for dog in collections.dogs.pages %}
  • A post snippet that is a menu of posts: {% for post in collections.posts.pages %}
    • ditto for collections: {% for dog in collections.dogs.pages %}
    • Particularly a generic one
  • A post snippet that links to the RSS: {{ collections.posts.rss_permalink }}
    • ditto for collectons: {{ collections.dogs.rss_permalink }}
    • Particularly a generic one
  • A page snippet that links to the posts RSS: {{ collections.posts.rss_permalink }}
    • ditto for an collection's RSS: {{ collections.dogs.rss_permalink }}

Prior Art

Cobalt today

  • posts have
    • posts: list of post attributes, containing everything but content / excerpt
    • is_post: boolean to know this s a post
  • pages have
    • posts: list of post attributes, containing everything
    • is_post: boolean to know this isn't a post

Hugo

Pages have:

  • RSSLink for taxonomy (collection?) the page is in
  • Site.RSSLink for site's rss
  • Site.Taxonomies.<name>.Pages: list of pages
    • within a taxonomy, these are available as .Data.Pages

Hugo

Jekyll

Page attributes

  • site.posts: list of posts
  • site.<name> list of pages
    • epage: We're trying to avoid mixing user-provided data with cobalt data to avoid breaking users on new additions
    • epage: Also, not all collections will be sorted, making this field type not always relevant.
  • site.collections.<name>: collection metadata (name, list of pages, etc)
  • collection: name of containing collection

Permalink

  • :collection name of the collection

Variables

@epage
Copy link
Member Author

epage commented Nov 2, 2017

The breaking change in here is that we'd need to switch posts from being just a list to being an object. that has a list child item

@epage epage self-assigned this Nov 2, 2017
@epage epage added this to the 0.10.0 milestone Nov 9, 2017
@epage epage changed the title Add posts variables Define behavior for is_post / posts Dec 20, 2017
@epage
Copy link
Member Author

epage commented Dec 20, 2017

Initial thought:

  • collection: metadata for current collection, including list of pages within it
  • (pages outside of any collection): collections.<name>: metadata for the given collection, including list of pages within it

Under this

  • is_post translates to collection.slug == "posts"
  • posts (within a post) translates to collection.pages
  • posts (in a non-collection page) translates to collections.posts.pages

Pros

  • Collections can reuse menus
    Cons
  • A bit verbose for the index pages
  • Makes it tricky to have a menu of posts shared between a page and a post
    • Example: site and source
    • Would require a {% assign collection = collections.posts %}
  • Can't show menu of posts on other collections

@epage
Copy link
Member Author

epage commented Dec 20, 2017

One option is to make collections available on all pages, just without page.excerpt and page.content.

But then it feels weird to have both collection and collections.<name> be the same thing.

But collection is nice for

@epage
Copy link
Member Author

epage commented Dec 30, 2017

Jekyl''s where filter seems to be helpful: {{ site.collections | where: "label", "myCollection" | first }}

See #350 for adding it in.

epage added a commit to epage/cobalt.rs that referenced this issue Dec 30, 2017
`page.collection` contains the collection slug which is `posts` for,
well, the built-in posts collection.

This is a step towards cobalt-org#323

BREAKING CHANGE: `page.is_post` is replaced by `page.collection`

Generally, it'll look like
`{% if page.is_post %}`
and can be replaced by
`{% if page.collection == "posts" %}`

though `cobalt migrate` should do this for you.
epage added a commit to epage/cobalt.rs that referenced this issue Dec 30, 2017
`page.collection` contains the collection slug which is `posts` for,
well, the built-in posts collection.

`collections.posts.pages` is a sorted list of all of the pages that are
part of the posts collection.

Fixes cobalt-org#323

BREAKING CHANGES:

`page.is_post` is replaced by `page.collection`.  Generally, it'll look like
`{% if page.is_post %}`
and can be replaced by
`{% if page.collection == "posts" %}`

`posts` is replaced by `collections.posts.pages`.  Generally, it'll look
like
`{% for post in posts %}`
and can be replaced by
`{% for post in collections.posts.pages %}`

`cobalt migrate` should do this for you.
epage added a commit to epage/cobalt.rs that referenced this issue Dec 30, 2017
`page.collection` contains the collection slug which is `posts` for,
well, the built-in posts collection.

`collections.posts.pages` is a sorted list of all of the pages that are
part of the posts collection.

Fixes cobalt-org#323

BREAKING CHANGES:

`page.is_post` is replaced by `page.collection`.  Generally, it'll look like
`{% if page.is_post %}`
and can be replaced by
`{% if page.collection == "posts" %}`

`posts` is replaced by `collections.posts.pages`.  Generally, it'll look
like
`{% for post in posts %}`
and can be replaced by
`{% for post in collections.posts.pages %}`

`cobalt migrate` should do this for you.
@epage epage closed this as completed in d280a35 Jan 6, 2018
epage added a commit that referenced this issue Jan 9, 2018
This release focused on unleashing a lot of breaking changes that have been
stacking up for a while which also expose a lot of features that have been
inaccessible.  The hope is that from now on, breaking changes will be minor
(like small changes to config) rather than sweeping changes to every file like
this.

Bug Fixes

*   Reducing logging noise ([a7acd2c](a7acd2c))
* **rss:**  Don't error if the RSS folder doesn't exist. ([357cb4b](357cb4b))
* **watch:**  Don't stop on error ([3c4d086](3c4d086), closes [#347](#347))

Features

*   Migrate support for changing _layouts to _includes ([28ae870](28ae870))
* **config:**
  *  Change .cobalt.yml to _cobalt.yml ([c4ee83b](c4ee83b), closes [#348](#348))
  *  Stablize the format ([34e9d54](34e9d54), closes [#199](#199), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/), [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **front:**
  *  Stablize fronmatter format ([9089c72](9089c72), closes [#257](#257), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Change date to YYYY-MM-DD ([1e19ae0](1e19ae0), closes [#349](#349), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Change permalink variable names ([e78b806](e78b806), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Change permalink to well-defined format ([c6c4d7a](c6c4d7a), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Standardize permalink behavior ([6730eb6](6730eb6), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **excerpt:**  Better define non-existent behavior ([129c574](129c574))
* **page:**
  *  Upgrade liquid ([2ec3f24](2ec3f24))
  *  Generalize is_post / posts ([d280a35](d280a35), closes [#323](#323), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Make page variables future-proof ([6f62dea](6f62dea), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  page.file.parent variable ([dce1d59](dce1d59), closes [#338](#338))
* **serve:**
  *  Adjust base_url for localhost ([e75e139](e75e139), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Merge `serve` and `watch` ([d2f22d5](d2f22d5), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **debug:**
  *  Report asset files ([5d77b7f](5d77b7f))
  *  Generalize debug commands ([087d991](087d991), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))

Breaking Changes

`cobalt migrate` was created to help mitigate the cost of most of these breaking changes.

* **config:**  Stablize the format ([34e9d54](34e9d54), closes [#199](#199), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/), [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **debug:**  Generalize debug commands ([087d991](087d991), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **front:**
  *  Change date to YYYY-MM-DD ([1e19ae0](1e19ae0), closes [#349](#349), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Change permalink variable names ([e78b806](e78b806), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Change permalink to well-defined format ([c6c4d7a](c6c4d7a), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Standardize permalink behavior ([6730eb6](6730eb6), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Stablize fronmatter format ([9089c72](9089c72), closes [#257](#257), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **page:**
  *  Liquid errors on undefined variables ([2ec3f24](2ec3f24))
    * This was done to help catch migration problems and to move us in the direction of easier debugging of problems
    * The restriction might be loosened in some cases (like `{% if var %}`).
  *  Generalize is_post / posts ([d280a35](d280a35), closes [#323](#323), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Make page variables future-proof ([6f62dea](6f62dea), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
* **serve:**
  *  Adjust base_url for localhost ([e75e139](e75e139), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))
  *  Merge `serve` and `watch` ([d2f22d5](d2f22d5), breaks [#](https://github.com/cobalt-org/cobalt.rs/issues/))

Performance

* **serve:**  Reduce duplicate rebuilds ([8f2679c](8f2679c))
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

1 participant