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

.File.Dir and .FilePath return absolute paths when used in directory based archetypes #7589

Closed
thomasmarkrea opened this issue Aug 22, 2020 · 4 comments · Fixed by #9045
Closed
Labels

Comments

@thomasmarkrea
Copy link

thomasmarkrea commented Aug 22, 2020

I have a directory based archetype and a standard archetype:

archetypes
├── test-bundle
│   └── index.md
└── test.md

Both .md files are identical and just include:

{{ .File.Dir }}

New content created from the standard archetype contains a path relative to content/ as expected (https://gohugo.io/variables/files/):

hugo new -k test blog/test.md
cat content/blog/test.md
# blog/

However, new content created from the directory based archetype contains the full path:

hugo new -k test-bundle blog/test
cat content/blog/test/index.md
# /home/tom/projects/test-hugo-dir/content/blog/test/

I assume the issue is somewhere in https://github.com/gohugoio/hugo/blob/master/create/content.go and the NewContent/newContentFromDir functions but my Hugo/Go knowledge is not enough to work out exactly what.


Example repository:
https://github.com/thomasmarkrea/test-hugo-dir


Related forum post:
https://discourse.gohugo.io/t/file-dir-returns-absolute-path/27621


What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.74.3-DA0437B4 linux/amd64 BuildDate: 2020-07-23T16:22:34Z

also tested on

$ hugo version
Hugo Static Site Generator v0.72.0-8A7EF3CF/extended linux/amd64 BuildDate: 2020-05-31T12:14:23Z

Does this issue reproduce with the latest release?

Yes

@jmooring
Copy link
Member

Confirmed. Reproduced with Hugo Static Site Generator v0.75.0-DEV/extended linux/amd64 BuildDate: unknown.

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 25, 2020
@jmooring
Copy link
Member

jmooring commented Apr 4, 2021

Possibly related:
https://discourse.gohugo.io/t/32155/6

When .File.Dir returns something like /home/tom/projects/test-hugo-dir/content/blog/test/ instead of blog/test/, .Section returns home instead of blog.

@stale stale bot removed the Stale label Apr 4, 2021
@jmooring jmooring changed the title .File.Dir returns an absolute path when used in directory based archetypes .File.Dir and .FilePath return absolute paths when used in directory based archetypes Oct 12, 2021
bep added a commit to bep/hugo that referenced this issue Oct 15, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
bep added a commit to bep/hugo that referenced this issue Oct 15, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
bep added a commit to bep/hugo that referenced this issue Oct 15, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
bep added a commit to bep/hugo that referenced this issue Oct 15, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
bep added a commit to bep/hugo that referenced this issue Oct 15, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
bep added a commit to bep/hugo that referenced this issue Oct 16, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
bep added a commit to bep/hugo that referenced this issue Oct 16, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
bep added a commit to bep/hugo that referenced this issue Oct 16, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes gohugoio#9032
Fixes gohugoio#7589
Fixes gohugoio#9043
Fixes gohugoio#9046
Fixes gohugoio#9047
@bep bep closed this as completed in #9045 Oct 16, 2021
bep added a commit that referenced this issue Oct 16, 2021
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template.

This new implementation is using the exact same code path for evaluating the pages as in a regular build.

This also makes it more robust and easier to reason about in a multilingual setup.

Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language:

```bash
hugo new content/en/posts/my-first-post.md
```

Fixes #9032
Fixes #7589
Fixes #9043
Fixes #9046
Fixes #9047
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants