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

AliasRedirects not working when files are moved into folders #904

Closed
vinceimbat opened this issue Feb 20, 2024 · 2 comments · May be fixed by #1681
Closed

AliasRedirects not working when files are moved into folders #904

vinceimbat opened this issue Feb 20, 2024 · 2 comments · May be fixed by #1681
Labels
bug Something isn't working

Comments

@vinceimbat
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

Aliases in the YAML frontmatter seem to stop working when files are moved into folders.

To Reproduce
Steps to reproduce the behavior:

  1. Create a file in the content folder.
  2. Add an alias to the file.
  3. (Alias redirect works.)
  4. Create a subfolder in the content folder (e.g., content/thoughts).
  5. Move the file into this subfolder.
  6. (Alias redirect fails and produces 404.)

Expected behavior
Alias redirect should work properly when moving files in folders.

Screenshots and Source

NA

Desktop (please complete the following information):

  • Quartz Version: v4.2.2
  • node Version: v19.4.0
  • npm version: v9.6.7
  • OS: OS X
  • Browser: Arc

Additional context

NA

@vinceimbat vinceimbat added the bug Something isn't working label Feb 20, 2024
@jackyzha0
Copy link
Owner

Alias redirects are relative to the full path, I use nested aliases in my own content and it works fine. Note that aliases are relative to the note and not absolute

@k3v53
Copy link

k3v53 commented Sep 3, 2024

I want to use aliases but I don't understand how should I write them.

Alias redirects are relative to the full path, I use nested aliases in my own content and it works fine. Note that aliases are relative to the note and not absolute

How do I use nested aliases? I tried setting an alias like /folder/note, folder/note and ../folder/note but none of them worked, I'm misunderstanding something?

Update: I've realized how is it supposed to work, the alias is relative to the note, so if you want to redirect from /folder/subfolder1/note to /folder/subfolder2/note the alias should be ../subfolder1/note but it will be explititly as is, it doesn't convert spaces into dashes so if you want to redirect because of a changed name dont write it like my note, write it like my-note instead.
I recommend copying from the url and then pasting it as the alias (correcting the relative path if you moved it into another folder of course)

necauqua added a commit to necauqua/beta-quartz that referenced this issue Dec 25, 2024
This is kind of hacky, but I haven't found a better way to augment
`allSlugs` - we need to have markdown parsed to get aliases from the
frontmatter, and we need to add the slugs before links get transformed
in the html plugin pass.

Fixes jackyzha0#904, don't know why you closed that
necauqua added a commit to necauqua/beta-quartz that referenced this issue Dec 25, 2024
Compute the alias FullSlugs in the frontmatter transformer and add them
to `allSlugs` there.
Also store them in file data to avoid recomputing them when emitting
alias redirect pages.

`allSlugs` need to be augmented before the html transformer resolves
the links, hence the move to the markdown transformer.

Fixes jackyzha0#904
necauqua added a commit to necauqua/beta-quartz that referenced this issue Dec 26, 2024
With markdownLinkResolution: "shortest", aka "+/- how Obsidian does it"
and given pages A and nested/B which has an alias Z, if you try to link
from A using [[Z]] it wouldn't work and get 404.

This is caused by alias slugs (nested/Z in this case, emitted by
AliasRedirects) not being present in the `allSlugs` list which is used
by the link transformer.

The fix is to compute the alias slugs in the frontmatter transformer
and add them to `allSlugs` there.
Also we store them in file data to avoid recomputing them when emitting
alias redirect pages.

Fixes jackyzha0#904

Note: given how currently the markdown/html transformers are ordered
this doesn't really work.

Given pages A and nested/B which has an alias Z, here's the order which
currently happens:

md-transformers(A) => html-transformers(A) =>
md-transformers(B) => html-transformers(B)

Since the nested/Z slug will get added when md-transformers(B) are run,
but the slugs are used by html-transformers(A) when resolving it's
links - the link [[Z]] in A will still 404

A fix for this is to split the parser into two stages - first apply the
md-transformers to all files, and only then apply html-transformers to
all files.

I did just that in a different commit, which is needed for this one to
work correctly.
necauqua added a commit to necauqua/beta-quartz that referenced this issue Jan 2, 2025
With markdownLinkResolution: "shortest", aka "+/- how Obsidian does it"
and given pages A and nested/B which has an alias Z, if you try to link
from A using [[Z]] it wouldn't work and get 404.

This is caused by alias slugs (nested/Z in this case, emitted by
AliasRedirects) not being present in the `allSlugs` list which is used
by the link transformer.

The fix is to compute the alias slugs in the frontmatter transformer
and add them to `allSlugs` there.
Also we store them in file data to avoid recomputing them when emitting
alias redirect pages.

Fixes jackyzha0#904

Note: given how currently the markdown/html transformers are ordered
this doesn't really work.

Given pages A and nested/B which has an alias Z, here's the order which
currently happens:

md-transformers(A) => html-transformers(A) =>
md-transformers(B) => html-transformers(B)

Since the nested/Z slug will get added when md-transformers(B) are run,
but the slugs are used by html-transformers(A) when resolving it's
links - the link [[Z]] in A will still 404

A fix for this is to split the parser into two stages - first apply the
md-transformers to all files, and only then apply html-transformers to
all files.

I did just that in a different commit, which is needed for this one to
work correctly.
necauqua added a commit to necauqua/beta-quartz that referenced this issue Jan 4, 2025
With markdownLinkResolution: "shortest", aka "+/- how Obsidian does it"
and given pages A and nested/B which has an alias Z, if you try to link
from A using [[Z]] it wouldn't work and get 404.

This is caused by alias slugs (nested/Z in this case, emitted by
AliasRedirects) not being present in the `allSlugs` list which is used
by the link transformer.

The fix is to compute the alias slugs in the frontmatter transformer
and add them to `allSlugs` there.
Also we store them in file data to avoid recomputing them when emitting
alias redirect pages.

Fixes jackyzha0#904

Note: given how currently the markdown/html transformers are ordered
this doesn't really work.

Given pages A and nested/B which has an alias Z, here's the order which
currently happens:

md-transformers(A) => html-transformers(A) =>
md-transformers(B) => html-transformers(B)

Since the nested/Z slug will get added when md-transformers(B) are run,
but the slugs are used by html-transformers(A) when resolving it's
links - the link [[Z]] in A will still 404

A fix for this is to split the parser into two stages - first apply the
md-transformers to all files, and only then apply html-transformers to
all files.

I did just that in a different commit, which is needed for this one to
work correctly.
necauqua added a commit to necauqua/beta-quartz that referenced this issue Jan 8, 2025
With markdownLinkResolution: "shortest", aka "+/- how Obsidian does it"
and given pages A and nested/B which has an alias Z, if you try to link
from A using [[Z]] it wouldn't work and get 404.

This is caused by alias slugs (nested/Z in this case, emitted by
AliasRedirects) not being present in the `allSlugs` list which is used
by the link transformer.

The fix is to compute the alias slugs in the frontmatter transformer
and add them to `allSlugs` there.
Also we store them in file data to avoid recomputing them when emitting
alias redirect pages.

Fixes jackyzha0#904

Note: given how currently the markdown/html transformers are ordered
this doesn't really work.

Given pages A and nested/B which has an alias Z, here's the order which
currently happens:

md-transformers(A) => html-transformers(A) =>
md-transformers(B) => html-transformers(B)

Since the nested/Z slug will get added when md-transformers(B) are run,
but the slugs are used by html-transformers(A) when resolving it's
links - the link [[Z]] in A will still 404

A fix for this is to split the parser into two stages - first apply the
md-transformers to all files, and only then apply html-transformers to
all files.

I did just that in a different commit, which is needed for this one to
work correctly.
necauqua added a commit to necauqua/beta-quartz that referenced this issue Jan 8, 2025
With markdownLinkResolution: "shortest", aka "+/- how Obsidian does it"
and given pages A and nested/B which has an alias Z, if you try to link
from A using [[Z]] it wouldn't work and get 404.

This is caused by alias slugs (nested/Z in this case, emitted by
AliasRedirects) not being present in the `allSlugs` list which is used
by the link transformer.

The fix is to compute the alias slugs in the frontmatter transformer
and add them to `allSlugs` there.
Also we store them in file data to avoid recomputing them when emitting
alias redirect pages.

Fixes jackyzha0#904

Note: given how currently the markdown/html transformers are ordered
this doesn't really work.

Given pages A and nested/B which has an alias Z, here's the order which
currently happens:

md-transformers(A) => html-transformers(A) =>
md-transformers(B) => html-transformers(B)

Since the nested/Z slug will get added when md-transformers(B) are run,
but the slugs are used by html-transformers(A) when resolving it's
links - the link [[Z]] in A will still 404

A fix for this is to split the parser into two stages - first apply the
md-transformers to all files, and only then apply html-transformers to
all files.

I did just that in a different commit, which is needed for this one to
work correctly.
necauqua added a commit to necauqua/beta-quartz that referenced this issue Jan 18, 2025
With markdownLinkResolution: "shortest", aka "+/- how Obsidian does it"
and given pages A and nested/B which has an alias Z, if you try to link
from A using [[Z]] it wouldn't work and get 404.

This is caused by alias slugs (nested/Z in this case, emitted by
AliasRedirects) not being present in the `allSlugs` list which is used
by the link transformer.

The fix is to compute the alias slugs in the frontmatter transformer
and add them to `allSlugs` there.
Also we store them in file data to avoid recomputing them when emitting
alias redirect pages.

Fixes jackyzha0#904

Note: given how currently the markdown/html transformers are ordered
this doesn't really work.

Given pages A and nested/B which has an alias Z, here's the order which
currently happens:

md-transformers(A) => html-transformers(A) =>
md-transformers(B) => html-transformers(B)

Since the nested/Z slug will get added when md-transformers(B) are run,
but the slugs are used by html-transformers(A) when resolving it's
links - the link [[Z]] in A will still 404

A fix for this is to split the parser into two stages - first apply the
md-transformers to all files, and only then apply html-transformers to
all files.

I did just that in a different commit, which is needed for this one to
work correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants