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

Path attribute in .md front-matter should be relative by default? #221

Closed
kylegach opened this issue Mar 29, 2016 · 9 comments
Closed

Path attribute in .md front-matter should be relative by default? #221

kylegach opened this issue Mar 29, 2016 · 9 comments

Comments

@kylegach
Copy link
Contributor

This is a suggestion, not a bug.

Given that one of the project’s goals is:

Intuitive directory-based URLs. The URL of a page is derived from its spot on the file system.

...it seems odd that the path attribute in the front-matter of an index.md file is always treated as absolute.

Imagine I have a directory structure:

/pages
    /writes
        /1-hello-world
            index.md
    /another-page
        index.md

And the front-matter of /pages/writes/1-hello-world/index.md includes:

path: "hello-world"

(note the lack of starting “/”)

Based on the goal quoted above, I'd expect the resulting URL to be /writes/hello-world. Currently, though, the resulting URL is /hello-world.

I realize I can simply leave off the path attribute (which results in /writes/1-hello-world), but I like using a preceding number or date to keep the pages in the correct order in the filesystem, and I would like that number or date to not be in the URL. Right now, the workaround is to add a path like “writes/hello-world”.

For people that like the current behavior, using an absolute instead of relative path could provide that.

I’m just diving into this stuff, but if someone can point me in the right direction, I’ll try to investigate further toward an eventual PR.

I also realize this is breaking change, so maybe it should just stay as-is.

@KyleAMathews
Copy link
Contributor

Hmmm... interesting point. I don't have a great intuition for this as I don't regularly hard-code paths in markdown files (part of my reason for wanting to derive urls from the directory position ;-)).

@gatsbyjs/gatsby-core-maintainers any thoughts?

@KyleAMathews
Copy link
Contributor

(there's also I should note the poorly documented rewritePath where you can programmatically rewrite paths to remove leading values from the path which is what I do on my blog)

@kylegach
Copy link
Contributor Author

That’ll probably work just fine for my needs. Thanks!

Edit:

Adding this to app.js works exactly as I need it to. But is there a way to remove the hard-coded “writes” parent directory name?

exports.rewritePath = function(parsedFilePath, metadata) {
  if (metadata.file.ext === 'md') {
    return "/writes/" + parsedFilePath.dirname.split('---')[1] + "/"
  }
}

@michaeljdeeb
Copy link
Contributor

Coming from Jekyll, I liked being able to separate out pages from posts in different directories and you could have a permalink option set in the site's config that would be applied to anything in the post directory.

With gatsby's focus on providing the minimal feature set and relying on plug-ins to fill in the gaps, I think building out a plug-in with rewritePath would be a good solution.

@KyleAMathews
Copy link
Contributor

@kylegach hard coded where? In the parsed file info?

@michaeljdeeb great point. I'm going to be working on fine-tuning/filling out the API + adding a plugin architecture soon so yeah, someone could create a plugin easily enough to add this sort of functionality.

@kylegach
Copy link
Contributor Author

Hard-coded in that snippet I included. Ideally, I could replace “writes” with some representation of the parent of parsedFilePath.dirname, but I don't know how or if it's possible.

@KyleAMathews
Copy link
Contributor

Ah ok. Yeah writes should be somewhere in the parsedFilePath object if you want to make this work across multiple directories.

@kylegach
Copy link
Contributor Author

kylegach commented Apr 9, 2016

It seems that #223 would make this a moot issue. Or rather, it shows that I had an incorrect understanding of the way the path is intended to work in front-matter.

@kylegach kylegach closed this as completed Apr 9, 2016
@KyleAMathews
Copy link
Contributor

Yeah I think defaulting to paths that are relative to the site root is the
simplest default. And with the future plunging architecture as Michael
mentioned someone could easily create a relative path plugin.
On Sat, Apr 9, 2016 at 4:03 PM kylegach notifications@github.com wrote:

It seems that #223 #223 would
make this a moot issue. Or rather, it shows that I had an incorrect
understanding of the way the path is intended to work in front-matter.


You are receiving this because you are on a team that was mentioned.

Reply to this email directly or view it on GitHub
#221 (comment)

ChristopherBiscardi added a commit to ChristopherBiscardi/gatsby that referenced this issue Jun 27, 2019
* Made componentWithMDXScope a no-op. It is deprecated and doesn't
  need to be used any more. MDXRenderer is still required for previous
  uses that required it.
* Scopes are now imported via custom webpack loader
  - TODO: rename mdx-scopes to the loaders dir
* Scopes are now merged into a single scope and injected into
  wrapRootElement on both SSR and Browser renders
* Querying code.scope is now a no-op
  - No files are written when this happens
* Relative path import support is added to all MDX Nodes

closes gatsbyjs#214 gatsbyjs#202 gatsbyjs#133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants