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

create child page should not include the "parent" filename in the GH repo path as it breaks github's preview tab #668

Closed
spkane opened this issue Aug 24, 2021 · 4 comments · Fixed by #1644

Comments

@spkane
Copy link

spkane commented Aug 24, 2021

Problem

When you click create child page on a docsy site, you end up with a URL that starts like this:

https://github.com/google/docsy-example/new/master/content/en/docs/_index.md?filename=change-me.md

CleanShot 2021-08-24 at 10 23 16

This works, unless you happen to actually look at the Preview tab, as this causes Github to compare the new change-me.md file with _index.md, which is not what the user is expecting (and not even what will happen when the PR is made).

CleanShot 2021-08-24 at 10 24 17

Fix

Fixing this simply requires that the parent filename is not included in the URL, like so:

https://github.com/google/docsy-example/new/master/content/en/docs/?filename=change-me.md

With this small change the preview now works as expected:

CleanShot 2021-08-24 at 10 26 46

Potential Code Change

There is likely a more elegant way to fix this upstream, so I am not creating a PR initially, but this is what I ended up doing to fix it locally.

diff --git a/layouts/partials/page-meta-links.html b/layouts/partials/page-meta-links.html
index 0bc5056..afaf5b0 100644
--- a/layouts/partials/page-meta-links.html
+++ b/layouts/partials/page-meta-links.html
@@ -1,5 +1,6 @@
 {{ if .Path }}
   {{ $pathFormatted := replace .Path "\\" "/" }}
+  {{ $dirFormatted := replace .Path "\\" "/" | path.Dir }}
   {{ $gh_repo := ($.Param "github_repo") }}
   {{ $gh_url := ($.Param "github_url") }}
   {{ $gh_subdir := ($.Param "github_subdir") }}
@@ -10,19 +11,23 @@
      <a href="{{ $gh_url }}" target="_blank"><i class="fa fa-edit fa-fw"></i> {{ T "post_edit_this" }}</a>
   {{ else if $gh_repo }}
     {{ $gh_repo_path := printf "%s/content/%s" $gh_branch $pathFormatted }}
+    {{ $gh_repo_dir := printf "%s/content/%s" $gh_branch $dirFormatted }}
     {{ if and ($gh_subdir) (.Site.Language.Lang) }}
       {{ $gh_repo_path = printf "%s/%s/content/%s/%s" $gh_branch $gh_subdir ($.Site.Language.Lang) $pathFormatted }}
+      {{ $gh_repo_dir = printf "%s/%s/content/%s/%s" $gh_branch $gh_subdir ($.Site.Language.Lang) $dirFormatted }}
     {{ else if .Site.Language.Lang }}
       {{ $gh_repo_path = printf "%s/content/%s/%s" $gh_branch ($.Site.Language.Lang) $pathFormatted }}
+      {{ $gh_repo_dir = printf "%s/content/%s/%s" $gh_branch ($.Site.Language.Lang) $dirFormatted }}
     {{ else if $gh_subdir }}
       {{ $gh_repo_path = printf "%s/%s/content/%s" $gh_branch $gh_subdir $pathFormatted }}
+      {{ $gh_repo_dir = printf "%s/%s/content/%s" $gh_branch $gh_subdir $dirFormatted }}
     {{ end }}
     {{ $editURL := printf "%s/edit/%s" $gh_repo $gh_repo_path }}
     {{ $createURL := printf "%s/edit/%s" $gh_repo $gh_repo_path }}
     {{ $issuesURL := printf "%s/issues/new?title=%s" $gh_repo (safeURL $.Title )}}
     {{ $newPageStub := resources.Get "stubs/new-page-template.md" }}
     {{ $newPageQS := querify "value" $newPageStub.Content "filename" "change-me.md" | safeURL }}
-    {{ $newPageURL := printf "%s/new/%s?%s"  $gh_repo $gh_repo_path $newPageQS }}
+    {{ $newPageURL := printf "%s/new/%s?%s"  $gh_repo $gh_repo_dir $newPageQS }}

     <a href="{{ $editURL }}" target="_blank"><i class="fa fa-edit fa-fw"></i> {{ T "post_edit_this" }}</a>
     <a href="{{ $newPageURL }}" target="_blank"><i class="fa fa-edit fa-fw"></i> {{ T "post_create_child_page" }}</a>
@gwatts
Copy link
Contributor

gwatts commented Aug 24, 2021

funny you should open this issue as I hit the same thing just a couple of days ago and was going to open a PR!

@mahi072
Copy link

mahi072 commented Mar 2, 2023

Hi @spkane, I would like to work on this issue.
Can you please direct me to the file where this changes to be made, if possible ??

@spkane
Copy link
Author

spkane commented Mar 4, 2023

@mahi072 The diff shows the file name at the top.

layouts/partials/page-meta-links.html

https://github.com/google/docsy/blob/main/layouts/partials/page-meta-links.html

mahi072 added a commit to mahi072/docsy that referenced this issue Mar 25, 2023
issue google#668
The proposed changes is the enhancement of the code to remove the parent filename in the GH repo path.
@mahi072
Copy link

mahi072 commented Mar 25, 2023

Hi @spkane,
I have raised the PR (#1488), Please review the changes.

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 a pull request may close this issue.

3 participants