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

drafts index page renders with incorrect links to draft articles if it doesnt have a trailing / #2841

Closed
2 tasks done
johnmathews opened this issue Jan 7, 2021 · 7 comments · Fixed by #2931
Closed
2 tasks done
Assignees
Labels

Comments

@johnmathews
Copy link

  • I have read the Filing Issues and subsequent “How to Get Help” sections of the documentation.

  • I have searched the issues (including closed ones) and believe that this is not a duplicate.

  • OS version and name: MacOS 11.0.1

  • Python version: 3.8.5

  • Pelican version: 4.5.3

  • Link to theme: my own theme

  • Links to plugins:
    nb_markup,
    'neighbors',
    'pelican.plugins.render_math',
    'pelican.plugins.sitemap',
    'pelican.plugins.simple_footnotes',
    'pelican.plugins.more_categories',

  • Link to your site: johnmathews.eu

  • **Link to Gist of local settings file

Issue

in my local settings file I have the following settings for viewing drafts (i believe this is the default)

DRAFT_SAVE_AS = 'drafts/{slug}.html'
DRAFT_URL = 'drafts/{slug}.html'

I launch a local server with: pelican --listen --autoreload

if I go to localhost:8000/drafts then I see the correct (complete) list of hyperlinks to each draft article, but the link urls are wrong. they are localhost:8000/<article-slug>.html but they should be localhost:8000/drafts/<article-slug>.html

If however, i goto localhost:8000/drafts/ (note the trailing /) then the links are correct and clicking on them sends the browser to the article.

Notwithstanding the incorrect links, the drafts index page seems to be identical in both cases.

This seems like a bug to me, but perhaps I've done something weird that I haven't spotted?

@johnmathews johnmathews added the bug label Jan 7, 2021
@avaris
Copy link
Member

avaris commented Jan 7, 2021

I'd check the relevant templates. Make sure they are in this form: note the explicit / between SITEURL and content URL.

@johnmathews
Copy link
Author

I'm not using any templates for the drafts index view.

@avaris
Copy link
Member

avaris commented Jan 8, 2021

Oh, you mean the default directory listing (the one you get without an index). Yes, I can replicate that. Trying with python -m http.server, seems like localhost:8000/drafts triggers a redirect to localhost:8000/drafts/ which makes things "work". We do override GET so, we might need to replicate that behavior.

@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your participation and understanding.

@stale stale bot added the stale Marked for closure due to inactivity label Mar 19, 2021
@stale stale bot removed the stale Marked for closure due to inactivity label Mar 20, 2021
@adiroiban
Copy link

I think that the fix for this is to have the embedded HTTP server enabled by --listen do an automatic redirect from /draft to /draft/ if 'draft' is a directory.

@avaris
Copy link
Member

avaris commented Oct 4, 2021

So the issue is:

  • Browser does GET /drafts
  • Server happily resolves it as GET /drafts/
  • Python server sees this and prepares a directory listing page
  • Directory listing lists files with relative urls
  • Browser looking at URL (still /drafts) considers the links as sibling instead of child since URL doesn't end with /

One solution is to redirect browser to /drafts/ then the links would be interpreted correctly.

We can let http.server default kick in and do its job, but annoyingly it does 301 Permanent Redirect. That sounds quite permanent for a temporary local server. 301s usually get cached in browser. So every time you type http://localhost:8000/drafts browser would "helpfully" do Nope, that was moved. I'm changing that to http://localhost:8000/drafts/.

Alternatively, we roll out our own redirect with 302 Found/Temporary redirect. That is slightly more involved than what I was hoping for.

Another solution is that we just make our own directory listing with absolute URLs.

@adiroiban
Copy link

I think that doing a redirect is good enough. No need for custom directory listing.
And a redirect might be closer to that you will get with a production server.

Either using the default http.server 301 or a custom 307 is better than the current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants