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

add trailing slash before anchors #3

Closed
wants to merge 1 commit into from

Conversation

rimrul
Copy link

@rimrul rimrul commented Oct 20, 2023

Changes

Modify the links that contain anchors to include a slash before the anchor to avoid the redirect.

Context

With Hugo and GitHub Pages there is a redirect for all folders to have a trailing slash that breaks anchors.

With Hugo and GitHub Pages there is a redirect for all folders to have a
trailing slash that breaks anchors. Modify the links that contain anchors to
include this slash and avoid the redirect.

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
xlink = html.scan(/href="(https:\/\/git-scm\.com\/.*?[^\/])\#(.*?)"/)
xlink&.each do |link|
begin
html.gsub!("href=\"#{link.first}\##{link[1]}\"", "href=\"#{link.first}/\##{link[1]}\"")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these should be converted to relative links in the process, instead of making them absolute again.
Also these are technically broken with this change since the absolute links still point to the rails site.

@dscho
Copy link
Owner

dscho commented Oct 24, 2023

With Hugo and GitHub Pages there is a redirect for all folders to have a trailing slash that breaks anchors.

I wonder if it would work if we added "slash-less" aliases to the target pages...

@dscho
Copy link
Owner

dscho commented Oct 24, 2023

I wonder if it would work if we added "slash-less" aliases to the target pages...

Ah, probably not because the .html file with the redirect would not preserve the anchor. That would require some Javascript hackery which Hugo's aliases: feature most likely does not provide.

A hack that seems to work over here is to add this step to the GitHub workflow:

find public -name \*.html -exec grep -Zl '<meta http-equiv="refresh"' {} \; |
xargs -0r sed -i '/<\/html>/i\
  <script>\
    window.location.replace(`${document.title}${window.location.hash}`)\
  </script>'

What do you think @rimrul?

@dscho
Copy link
Owner

dscho commented Oct 24, 2023

Oh, I think I found something: https://gohugo.io/getting-started/configuration/#uglyurls. We may want to do that, and then also ensure that /docs.html is the actual file (I verified that the .html-less URL resolves to the .html file, see e.g. https://dscho.github.io/scalar) and /docs/index.html is just a redirect.

What do you think @rimrul?

@rimrul
Copy link
Author

rimrul commented Oct 25, 2023

Oh, I think I found something: https://gohugo.io/getting-started/configuration/#uglyurls. We may want to do that, and then also ensure that /docs.html is the actual file (I verified that the .html-less URL resolves to the .html file, see e.g. https://dscho.github.io/scalar) and /docs/index.html is just a redirect.

What do you think @rimrul?

That should work. I came across that setting, but read that as having to use the .html URLs. Seeing https://dscho.github.io/scalar, that's probably not the case.

@dscho
Copy link
Owner

dscho commented Nov 6, 2023

Oh, I think I found something: https://gohugo.io/getting-started/configuration/#uglyurls. We may want to do that, and then also ensure that /docs.html is the actual file (I verified that the .html-less URL resolves to the .html file, see e.g. https://dscho.github.io/scalar) and /docs/index.html is just a redirect.
What do you think @rimrul?

That should work. I came across that setting, but read that as having to use the .html URLs. Seeing https://dscho.github.io/scalar, that's probably not the case.

I believe that this is working on https://dscho.github.io/git-scm.com/ now.

@dscho dscho closed this Nov 6, 2023
dscho added a commit that referenced this pull request Apr 1, 2024
# The 1st commit message will be skipped:

# ci: update the books via a GitHub workflow
#
# With this commit, the SHAs corresponding to the various repositories
# containing the ProGit Book and its translations are stored in a
# sparse-checkout'able directory.
#
# This information is then used by a scheduled workflow to determine what
# needs to be updated (if anything) and then performing that task.
#
# Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #2 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #3 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# This is the commit message #4:

# amend! ci: update the books via a GitHub workflow

ci: update the books via a GitHub workflow

With this commit, the SHAs corresponding to the various repositories
containing the ProGit Book and its translations are stored in a
sparse-checkout'able directory.

This information is then used by a scheduled workflow to determine what
needs to be updated (if anything) and then performing that task.

When GitHub workflows push new changes, they cannot trigger other GitHub
workflows (to avoid infinite loops). Therefore, this new GitHub workflow
not only synchronizes the books, but also builds the site and deploys
it.

Note: The code to build the site and to deploy it is provided in a
custom Action, to make it reusable. It will come in handy over the next
commits, where other GitHub workflows are added that likewise need
to synchronize changes that desire a site rebuild & deployment.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #5 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #6 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #7 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #8 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message git#9 will be skipped:

# fixup! ci: update the books via a GitHub workflow
dscho added a commit that referenced this pull request Apr 1, 2024
# The 1st commit message will be skipped:

# ci: update the books via a GitHub workflow
#
# With this commit, the SHAs corresponding to the various repositories
# containing the ProGit Book and its translations are stored in a
# sparse-checkout'able directory.
#
# This information is then used by a scheduled workflow to determine what
# needs to be updated (if anything) and then performing that task.
#
# Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #2 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #3 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# This is the commit message #4:

# amend! ci: update the books via a GitHub workflow

ci: update the books via a GitHub workflow

With this commit, the SHAs corresponding to the various repositories
containing the ProGit Book and its translations are stored in a
sparse-checkout'able directory.

This information is then used by a scheduled workflow to determine what
needs to be updated (if anything) and then performing that task.

When GitHub workflows push new changes, they cannot trigger other GitHub
workflows (to avoid infinite loops). Therefore, this new GitHub workflow
not only synchronizes the books, but also builds the site and deploys
it.

Note: The code to build the site and to deploy it is provided in a
custom Action, to make it reusable. It will come in handy over the next
commits, where other GitHub workflows are added that likewise need
to synchronize changes that desire a site rebuild & deployment.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #5 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #6 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #7 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #8 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message git#9 will be skipped:

# fixup! ci: update the books via a GitHub workflow
dscho added a commit that referenced this pull request Apr 1, 2024
# The 1st commit message will be skipped:

# ci: update the books via a GitHub workflow
#
# With this commit, the SHAs corresponding to the various repositories
# containing the ProGit Book and its translations are stored in a
# sparse-checkout'able directory.
#
# This information is then used by a scheduled workflow to determine what
# needs to be updated (if anything) and then performing that task.
#
# Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #2 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #3 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# This is the commit message #4:

# amend! ci: update the books via a GitHub workflow

ci: update the books via a GitHub workflow

With this commit, the SHAs corresponding to the various repositories
containing the ProGit Book and its translations are stored in a
sparse-checkout'able directory.

This information is then used by a scheduled workflow to determine what
needs to be updated (if anything) and then performing that task.

When GitHub workflows push new changes, they cannot trigger other GitHub
workflows (to avoid infinite loops). Therefore, this new GitHub workflow
not only synchronizes the books, but also builds the site and deploys
it.

Note: The code to build the site and to deploy it is provided in a
custom Action, to make it reusable. It will come in handy over the next
commits, where other GitHub workflows are added that likewise need
to synchronize changes that desire a site rebuild & deployment.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #5 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #6 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #7 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #8 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message git#9 will be skipped:

# fixup! ci: update the books via a GitHub workflow
dscho added a commit that referenced this pull request May 10, 2024
# The 1st commit message will be skipped:

# ci: update the books via a GitHub workflow
#
# With this commit, the SHAs corresponding to the various repositories
# containing the ProGit Book and its translations are stored in a
# sparse-checkout'able directory.
#
# This information is then used by a scheduled workflow to determine what
# needs to be updated (if anything) and then performing that task.
#
# Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #2 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #3 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# This is the commit message #4:

# amend! ci: update the books via a GitHub workflow

ci: update the books via a GitHub workflow

With this commit, the SHAs corresponding to the various repositories
containing the ProGit Book and its translations are stored in a
sparse-checkout'able directory.

This information is then used by a scheduled workflow to determine what
needs to be updated (if anything) and then performing that task.

When GitHub workflows push new changes, they cannot trigger other GitHub
workflows (to avoid infinite loops). Therefore, this new GitHub workflow
not only synchronizes the books, but also builds the site and deploys
it.

Note: The code to build the site and to deploy it is provided in a
custom Action, to make it reusable. It will come in handy over the next
commits, where other GitHub workflows are added that likewise need
to synchronize changes that desire a site rebuild & deployment.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #5 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #6 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #7 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #8 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message git#9 will be skipped:

# fixup! ci: update the books via a GitHub workflow
dscho added a commit that referenced this pull request May 26, 2024
# The 1st commit message will be skipped:

# ci: update the books via a GitHub workflow
#
# With this commit, the SHAs corresponding to the various repositories
# containing the ProGit Book and its translations are stored in a
# sparse-checkout'able directory.
#
# This information is then used by a scheduled workflow to determine what
# needs to be updated (if anything) and then performing that task.
#
# Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #2 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #3 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# This is the commit message #4:

# amend! ci: update the books via a GitHub workflow

ci: update the books via a GitHub workflow

With this commit, the SHAs corresponding to the various repositories
containing the ProGit Book and its translations are stored in a
sparse-checkout'able directory.

This information is then used by a scheduled workflow to determine what
needs to be updated (if anything) and then performing that task.

When GitHub workflows push new changes, they cannot trigger other GitHub
workflows (to avoid infinite loops). Therefore, this new GitHub workflow
not only synchronizes the books, but also builds the site and deploys
it.

Note: The code to build the site and to deploy it is provided in a
custom Action, to make it reusable. It will come in handy over the next
commits, where other GitHub workflows are added that likewise need
to synchronize changes that desire a site rebuild & deployment.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #5 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #6 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #7 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #8 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message git#9 will be skipped:

# fixup! ci: update the books via a GitHub workflow
dscho added a commit that referenced this pull request Jun 11, 2024
# The 1st commit message will be skipped:

# ci: update the books via a GitHub workflow
#
# With this commit, the SHAs corresponding to the various repositories
# containing the ProGit Book and its translations are stored in a
# sparse-checkout'able directory.
#
# This information is then used by a scheduled workflow to determine what
# needs to be updated (if anything) and then performing that task.
#
# Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #2 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #3 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# This is the commit message #4:

# amend! ci: update the books via a GitHub workflow

ci: update the books via a GitHub workflow

With this commit, the SHAs corresponding to the various repositories
containing the ProGit Book and its translations are stored in a
sparse-checkout'able directory.

This information is then used by a scheduled workflow to determine what
needs to be updated (if anything) and then performing that task.

When GitHub workflows push new changes, they cannot trigger other GitHub
workflows (to avoid infinite loops). Therefore, this new GitHub workflow
not only synchronizes the books, but also builds the site and deploys
it.

Note: The code to build the site and to deploy it is provided in a
custom Action, to make it reusable. It will come in handy over the next
commits, where other GitHub workflows are added that likewise need
to synchronize changes that desire a site rebuild & deployment.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

# The commit message #5 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #6 will be skipped:

# fixup! fixup! ci: update the books via a GitHub workflow

# The commit message #7 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message #8 will be skipped:

# fixup! ci: update the books via a GitHub workflow

# The commit message git#9 will be skipped:

# fixup! ci: update the books via a GitHub workflow
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

Successfully merging this pull request may close these issues.

None yet

3 participants