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

the archives, tags and categories didn't display on a nginx server #276

Closed
josephzjw opened this issue Feb 7, 2019 · 12 comments

Comments

@josephzjw
Copy link

@josephzjw josephzjw commented Feb 7, 2019

When I use pelican -l in the localhost everything is okay, but when I publish the output to the nginx server it shows 404 not found error. Other pages are correct. I found that all the archives, tags and categories are directories in the output file. Their names are archive, tag and category. Is it mismatched with the name that cause the problem?

When I switch to another theme with tag and archive available, everything is okay... So I guess the problem is not my configuration of nginx server...

@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Feb 10, 2019

@josephzjw You will have to provide source code of your blog along with the configuration file so that we can test and try to reproduce the issue at our end.

But first, we had a similar issue sometime ago. Please go through it and see if it helps.

#250

@josephzjw

This comment has been minimized.

Copy link
Author

@josephzjw josephzjw commented Feb 10, 2019

It works when I followed the instructions you provided #250 Thanks!
By the way, why at localhost I don't need to specify the archives, tags and categories url and they still work correctly....

@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Feb 10, 2019

I followed the instructions you provided

@josephzjw hmm, can you please write here what worked for you. We may need to add it to documentation.

@josephzjw

This comment has been minimized.

Copy link
Author

@josephzjw josephzjw commented Feb 10, 2019

I followed the solution of azzamsa, add the three line codes below at the pelicanconf.py

TAGS_URL = 'tags.html'
CATEGORIES_URL = 'categories.html'
ARCHIVES_URL = 'archives.html'

Then I use pelican to generate the website and type service nginx reload to reload the nginx service. Finally it works...

@talha131 talha131 added this to the Elegant 2.2 milestone Feb 10, 2019
@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Feb 10, 2019

Thank you @josephzjw We will look into it in detail. According to my understanding Elegant should have worked out of the box. We will either fix our code or update our documentation.

@alxpettit

This comment has been minimized.

Copy link

@alxpettit alxpettit commented Mar 6, 2019

I can confirm this issue. The reason it happens is because the nav bar is rendered with links pointing to e.g. site.com/archives instead of site.com/archives.html -- I'm not sure if other servers automatically add a .html for blank queries, but nginx does not do this -- and it results in a 404.

To fix this, I just added an explicit .html to each URL generator in base.html:

<li {% if page_name == 'categories' %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ CATEGORIES_URL|default('categories.html') }}">Categories</a></li>
<li {% if page_name == 'tags' %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ TAGS_URL|default('tags.html') }}">Tags</a></li>
<li {% if page_name == 'archives' %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ ARCHIVES_URL|default('archives.html') }}">Archives</a></li>

You should be able to do the same in a commit and get it working on nginx without interfering with functionality on other servers, I believe.

Edit: I went ahead and made a pull request. Hope it's useful! :)

Edit 2: looks like although my pull request fixes the problem with the menu buttons, there are still broken links elsewhere. For instance all posts under Home has another instance of default('archives') that needs to be changed. Darn. Sorry I missed that.

This was referenced Mar 6, 2019
@talha131 talha131 modified the milestones: Elegant 2.2, Elegant 2.3, 2019 - Q3 Jun 10, 2019
@andrewdstrain

This comment has been minimized.

Copy link

@andrewdstrain andrewdstrain commented Jul 23, 2019

This issue doesn't affect just Nginx and josephzjw's fix, above, shouldn't be needed because the templates give the wrong default values. alxpettit's fix does work but more files need to be changed than just base.html.

To generate the issue:

Try twistd -on web --path=output on any Pelican website with the Elegant theme (from master or next branch) and the URLs generated will fail.

twistd example

If you look at the source code, you see code like this:

<a class="category-link" href="{{ SITEURL }}/{{ CATEGORIES_URL|default('categories') }}#{{ category.slug }}-ref">{{ article.category }}</a>

The problem is in the default('categories') part of the code. Pelican, by default, generates 'categories.html', not 'categories'. When using the pelican -l command as a web server, the wrong default works because the web server adds .html to the URL that isn't found. That is, you can have both http://localhost:8000/index and http://localhost:800/index.html and the Pelican web server will pull up the same file. Other web servers, like Nginx, twistd -on web --path=output, Apache, etc., don't do that by default and can not find http://localhost:8000/index at all.

This Diff is how I fixed the problem in the template code of the Elegant theme.

elegant.diff.txt

@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Jul 23, 2019

Thank you @andrewdstrain. I will look into it in detail and get back to you.

talha131 added a commit that referenced this issue Aug 10, 2019
… some servers

In the first version of the theme, we had hard coded ".html" to URLs
like "tags.html".

Later it was made configurable via ARCHIVES_URL, CATEGORIES_URL, and
TAGS_URL. But the default values of these variables were incorrectly
set to "tags", "categories" and "archives".

This broke on several servers that didn't append ".html" to URLs
automatically.

With this patch, the default value of these variables is "*.html".
This theme should work out of the box on all servers.

BREAKING CHANGE: To enable clean URLs for tags, categories and archives,
first configure your server to support clean URLs. Then set `TAGS_URL`,
`CATEGORIES_URL` and `ARCHIVES_URL` to `"tags"`, `"categories"` and
`"archives"` respectively.

fix #280
fix #276
@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Aug 10, 2019

I have fixed this issue in here

#480

It's available on the next branch. It will release to master in couple of days.

@andrewdstrain I am specially thankful to you for explaining the issue in detail. If you greatly appreciate if you can manage sometime to review my fix. This is the commit which fixes the issue 3c7df6a

@talha131 talha131 closed this Aug 10, 2019
@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Aug 10, 2019

@all-contributors please add @josephzjw for bug

@allcontributors

This comment has been minimized.

Copy link
Contributor

@allcontributors allcontributors bot commented Aug 10, 2019

@talha131

I've put up a pull request to add @josephzjw! 🎉

talha131 pushed a commit that referenced this issue Aug 22, 2019
# [4.0.0](V3.2.0...V4.0.0) (2019-08-22)

### Bug Fixes

* **admonition:** an artifact in border behind the title ([88113c3](88113c3))
* **admonition:** reduce border radius to match radii of other components ([de08d20](de08d20)), closes [#490](#490)
* **admonition:** remove box shadow ([d059db8](d059db8)), closes [#490](#490)
* **admonition:** remove text-shadow from heading ([1c889da](1c889da)), closes [#490](#490)
* **clean URL:** default URL of categories, tags and archives fails on some servers ([3c7df6a](3c7df6a)), closes [#280](#280) [#276](#276)
* **comments:** W3C validation errors ([76a1f26](76a1f26))
* **disqus:** remove SITEURL condition to show Disqus comments section ([753d5a5](753d5a5))
* **lang:** do not override default value of DEFAULT_LANG set by Pelican ([d6c60c2](d6c60c2))
* **social:** reduce icon sizes in the sidebar ([c769ba3](c769ba3))
* **social:** use nofollow for social links in the sidebar ([50cff87](50cff87))
* **social:** W3C validation error ([ec4521e](ec4521e))
* **table:** reduce border radius to match radii of other components ([7eaaa96](7eaaa96))
* **w3c validation:** remove incorrect usage of article tag ([e8231e0](e8231e0)), closes [#251](#251)
* **w3c validation:** remove obsolete charset attribute ([8deb285](8deb285)), closes [#251](#251)
* **w3c validation:** remove redundant article tag ([d07c27e](d07c27e)), closes [#251](#251)
* **w3c validation:** remove redundant sections without heading ([df9221f](df9221f)), closes [#251](#251)
* **w3c validation:** remove type and language attributes ([b700224](b700224)), closes [#251](#251)
* **w3c validation:** update CSS rules ([0b78d46](0b78d46)), closes [#251](#251)

### Features

* **404:** auto fill search box with URL fragment that was not found ([c0a7f47](c0a7f47))
* **admonition:** add box shadow ([246f826](246f826))
* **admonition:** border color should match the title color ([1adadbe](1adadbe))
* **admonition:** increase contrast of title ([7fb82cc](7fb82cc))
* **admonition:** use svg image instead of font-awesome icon ([e7c4029](e7c4029)), closes [#487](#487)
* **clean url:** support clean URL for search page ([088791e](088791e))
* **comments:** add support for utterances comment system ([a2151cc](a2151cc)), closes [#288](#288)
* **quotes:** improve style and remove font-awesome for quote icon ([9ef3ac8](9ef3ac8)), closes [#487](#487)
* **social:** add icons for 7 more websites ([8dcf8fa](8dcf8fa)), closes [#494](#494)
* **social:** use svg icons instead of font-awesome ([19f458b](19f458b))
* **table:** add style rule to make tables pop out ([6a8500b](6a8500b)), closes [#440](#440)

### Performance Improvements

* **admonition:** add attributes to svg iamges ([a740a60](a740a60))
* **requests:** remove font awesome ([7c20145](7c20145)), closes [#487](#487)

### BREAKING CHANGES

* **requests:** We have removed font awesome. Now we use svg images for all icons. This will result
in one less web request, which in turn will improve your websites performance.
* **social:** Style customization and configuration of social icons
in the sidebar has changed.

New icons have better colors and bigger sizes.
* **clean URL:** To enable clean URLs for tags, categories and archives,
first configure your server to support clean URLs. Then set `TAGS_URL`,
`CATEGORIES_URL` and `ARCHIVES_URL` to `"tags"`, `"categories"` and
`"archives"` respectively.
@talha131

This comment has been minimized.

Copy link
Member

@talha131 talha131 commented Aug 22, 2019

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@talha131 talha131 added the released label Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.