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

Static files with custom paths #338

Closed
tkornack opened this issue Dec 2, 2017 · 9 comments
Closed

Static files with custom paths #338

tkornack opened this issue Dec 2, 2017 · 9 comments
Assignees
Labels
enhancement Improve the expected
Milestone

Comments

@tkornack
Copy link

tkornack commented Dec 2, 2017

Let's say you have a post in a subdirectory, posts/post_dir/ with some static files/images. This builds:

  • The page at the custom path: /custom-post-path/index.html
  • The images at the posts path, like /posts/post_dir/image.jpg

Is there a way to obtain reference where those images wind up so that I don't have to hard code the path? "/posts/{{source}}" almost works, but I only want the path, without the page file. I could use something like "/posts/{{source_path}}"? Otherwise I have to hard code the paths to the static files. Copying the images to the custom path, I imagine, is a non-starter because they might be referenced by more than one pages.

@epage
Copy link
Member

epage commented Dec 2, 2017

So let me see if I understand.

You keep your post and its assets in a folder but are using a custom path for the post. This means you can't just use a relative path to the assets because they end up in a different location. So you'd like some way of knowing where they end up.

One solution would be to expose a variable to your post that is the path it would exist in if you didn't use a custom path. The hard thing will be to come up with a meaningful name for this. Suggestions?

@epage
Copy link
Member

epage commented Dec 2, 2017

Also, to talk real quick on workflows.

I assumed people would take one of two approaches

  • Standard-path posts with assets next to them (same location in source and dest)
  • Custom-path posts with assets in a dedicated folder (different locations in source and dest)

What you seem to be doing is a hybrid

  • Assets and posts in the same location in the source but different locations in the dest.

Could you help me understand why you chose this workflow?

Why is this helpful?

  • I might document workflows as part of Setup cobalt website #73 and understanding what people want to do and why is helpful
  • Help in naming the variable if we go that route.
  • We might decide this is an obscure enough workflow that it would detract from the UX for everyone else to build-in support for this.

@tkornack
Copy link
Author

tkornack commented Dec 2, 2017

Hi! Thanks for the reply. For context, the site is Twinleaf. We're using custom-path posts for products. It would just be handy to have the assets in the same folder as the post in this case: keeps the thing photos with the thing page.

Honestly I was just looking for a handy templating system and just bent cobalt posts to our needs.
You can see that we could build a fully static directory tree with templates applied to the pages in that structure.

@epage
Copy link
Member

epage commented Dec 2, 2017

Cool!

Honestly I was just looking for a handy templating system and just bent cobalt posts to our needs.

Down the road, I plan to generalize support for "posts" so you can have custom defined "collections" so it'll seem like less of an abuse of cobalt :)

It would just be handy to have the assets in the same folder as the post in this case: keeps the thing photos with the thing page.

And I think that can be neat. The hard part is coming up with how to configure this so it makes sense.

@tkornack
Copy link
Author

tkornack commented Dec 3, 2017

Having a {{source_dir}} that I could place before each image link would work for now. Same as {{source}} without the file name.

@epage epage added the enhancement Improve the expected label Dec 4, 2017
@epage
Copy link
Member

epage commented Dec 4, 2017

I think doing that minimal level is reasonable.

btw I was considering getting rid of {{source}} because I can't see why it'd be useful yo anyone.

@tkornack
Copy link
Author

tkornack commented Dec 4, 2017

Agreed on the uselessness of {{source}}.

@epage
Copy link
Member

epage commented Dec 5, 2017

The reason for {{source_dir}} is to access content without a custom path. We've discussed source to communicate this. Another option is assets

Currently document's have path for their URL (mostly useful from other documents accessing the posts variable), so for consistency path might be better than dir.

So another option {{assets_path}}.

When implementing features, I like to also consider prior art

  • Jekyll
    • page.url: path to rendered page
    • page.path path to unrendered page
  • Hugo
    • .Permalink: path to rendered page (I think)
    • .RelPermalink: relative path to rendered page (I think)
    • .URL: URL for page relative to webroot (how is this different than .Permalink?)
    • .Dir: directory of unrendered page (I think)
    • .File.Path: path to unrendered page
    • .File.Dir: documentation for this is confusing

I feel like Hugo's File makes it nice and explicit.

(sorry if it feels I'm over thinking this;; I'm trying to plan features ahead of time to avoid changing them and disrupting people. I've already got one major disruption planned, I'd rather not have more).

Agreed on the uselessness of {{source}}.

Found the reason for it:

The path to the raw post or page. Example usage: Linking back to the page or post’s source on GitHub

https://jekyllrb.com/docs/variables/#page-variables

@epage epage added this to the 0.10.1 milestone Dec 23, 2017
@epage epage self-assigned this Jan 6, 2018
epage added a commit to epage/cobalt.rs that referenced this issue Jan 6, 2018
This can be used for referencing assets in the folder the file came
from.

Fixes cobalt-org#338
@epage epage closed this as completed in #358 Jan 6, 2018
@tkornack
Copy link
Author

tkornack commented Jan 8, 2018

Perfect. Thanks.

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
Labels
enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

2 participants