Skip to content

Commit

Permalink
feat(clean url): support clean URL for search page
Browse files Browse the repository at this point in the history
  • Loading branch information
talha131 committed Aug 10, 2019
1 parent a837c28 commit 088791e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions documentation/content/Advanced Features/clean-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ For pages, set
PAGE_URL = "{slug}"
PAGE_SAVE_AS = "{slug}.html"
```

## Search

For search page, set

```python
SEARCH_URL = "search"
```
1 change: 1 addition & 0 deletions documentation/pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
TAGS_URL = "tags"
CATEGORIES_URL = "categories"
ARCHIVES_URL = "archives"
SEARCH_URL = "search"

# Feeds
AUTHOR_FEED_ATOM = None
Expand Down
3 changes: 2 additions & 1 deletion templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ <h1>That page doesn't exist!</h1>
<p>Sorry, but the page you are looking for cannot be found. It seems that the page you were trying to reach doesn't exist, or may be it has just moved, or it no longer exists.</p>
<p>The best thing to do is to use the search form or start again from the <a href="{{ SITEURL }}">home page</a>.</p>
<div class="input-append">
<form action="{{ SITEURL }}/search.html" onsubmit="return validateForm(this.elements['q'].value)">
{% from '_includes/_defaults.html' import SEARCH_URL with context %}
<form action="{{ SITEURL }}/{{ SEARCH_URL }}" onsubmit="return validateForm(this.elements['q'].value)">
<input type="text" class="span12" placeholder="Search" name="q" id="tipue_search_input_404">
<button class="btn" type="submit">Search</button>
</form>
Expand Down
6 changes: 6 additions & 0 deletions templates/_includes/_defaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@
{% else %}
{% set ARCHIVES_URL = ARCHIVES_URL %}
{% endif %}

{%if not SEARCH_URL %}
{% set SEARCH_URL = 'search.html' %}
{% else %}
{% set SEARCH_URL = SEARCH_URL %}
{% endif %}
4 changes: 2 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
<li {% if p == page %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ p.url }}">{{ p.title }}</a></li>
{% endfor %}
{% endif %}
{% from '_includes/_defaults.html' import TAGS_URL, CATEGORIES_URL, ARCHIVES_URL with context %}
{% from '_includes/_defaults.html' import TAGS_URL, CATEGORIES_URL, ARCHIVES_URL, SEARCH_URL with context %}
<li {% if page_name == 'categories' %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ CATEGORIES_URL }}">Categories</a></li>
<li {% if page_name == 'tags' %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ TAGS_URL }}">Tags</a></li>
<li {% if page_name == 'archives' %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ ARCHIVES_URL }}">Archives</a></li>
<li><form class="navbar-search" action="{{ SITEURL }}/search.html" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
<li><form class="navbar-search" action="{{ SITEURL }}/{{ SEARCH_URL }}" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
</ul>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

{% block meta_tags_in_head %}
{{ super() }}
{% from '_includes/_defaults.html' import FEATURED_IMAGE, SEARCH_URL with context %}
<meta property="og:title" content="Search · {{ SITENAME|striptags|e }}"/>
<meta name="twitter:title" content="Search · {{ SITENAME|striptags|e }}">
<meta property="og:url" content="{{ SITEURL }}/search.html" />
<meta property="og:url" content="{{ SITEURL }}/{{ SEARCH_URL }}" />
<meta property="og:description" content="Search results for {{ SITENAME|striptags|e }} blog" />
<meta name="twitter:description" content="Search results for {{ SITENAME|striptags|e }} blog">
<meta property="og:site_name" content="{{ SITENAME|striptags|e }}" />
<meta property="og:article:author" content="{{ AUTHOR }}" />
{% from '_includes/_defaults.html' import FEATURED_IMAGE with context %}
{% if FEATURED_IMAGE %}
<meta property="og:image" content="{{FEATURED_IMAGE}}" />
<meta name="twitter:image" content="{{FEATURED_IMAGE}}" >
Expand Down

0 comments on commit 088791e

Please sign in to comment.