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

Added search modes and extra functions #838

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 126 additions & 6 deletions app/default-files/default-themes/simple/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -869,22 +869,59 @@
"value": false,
"type": "checkbox"
},
{
"name": "searchMode",
"label": "Mode",
"group": "Search",
"note": "The <strong>external</strong> mode allows you to search from any external search engine.<br/>The <strong>integrated</strong> mode will integrate the search results on your website.",
"value": "external",
"type": "radio",
"dependencies": [{
"field": "search",
"value": "true"
}],
"options": [
{
"label": "External",
"value": "external"
},
{
"label": "Integrated",
"value": "integrated"
}
]
},
{
"name": "searchId",
"name": "separator",
"type": "separator",
"label": "Search configuration",
"group": "Search",
"label": "Google Custom Search Id",
"note": "A search ID is required for search functionality, which uses Google Custom Search. Learn how to configure it here: <a href='https://getpublii.com/docs/search-configuration.html' target='_blank'>https://www.getpublii.com/docs/...</a>",
"value": "",
"type": "text",
"size": "big",
"dependencies": [{
"field": "search",
"value": "true"
}]
},
{
"name": "searchServer",
"group": "Search",
"label": "Engine",
"note": "Enter the URL of the search engine you want to use on your website.",
"value": "https://duckduckgo.com",
"type": "url",
"dependencies": [{
"field": "search",
"value": "true"
},
{
"field": "searchMode",
"value": "external"
}]
},
{
"name": "searchParam",
"group": "Search",
"label": "Search parameter",
"label": "Parameter",
"note": "You can change the default \"q\" search parameter if desired; this is recommended only for advanced users.",
"value": "q",
"type": "text",
Expand All @@ -893,6 +930,89 @@
"value": "true"
}]
},
{
"name": "searchMethod",
"label": "Form Method",
"group": "Search",
"note": "Select the method you want to use for your search engine.",
"value": "get",
"type": "radio",
"dependencies": [{
"field": "search",
"value": "true"
},
{
"field": "searchMode",
"value": "external"
}],
"options": [
{
"label": "Post",
"value": "post"
},
{
"label": "Get",
"value": "get"
}
]
},
{
"name": "searchTab",
"label": "Open results in new tab",
"group": "Search",
"value": false,
"type": "checkbox",
"dependencies": [{
"field": "search",
"value": "true"
}]
},
{
"name": "searchForceWebsiteResults",
"label": "Only show results from your website",
"group": "Search",
"value": true,
"type": "checkbox",
"dependencies": [{
"field": "search",
"value": "true"
},
{
"field": "searchMode",
"value": "external"
}]
},
{
"name": "separator",
"type": "separator",
"label": "Google search configuration",
"group": "Search",
"size": "big",
"dependencies": [{
"field": "search",
"value": "true"
},
{
"field": "searchMode",
"value": "integrated"
}]
},
{
"name": "searchId",
"group": "Search",
"label": "Custom Search Id",
"note": "A search ID is required for integrated mode functionality, which uses Google Custom Search. Learn how to configure it here: <a href='https://getpublii.com/docs/search-configuration.html' target='_blank'>https://www.getpublii.com/docs/...</a>",
"value": "",
"type": "text",
"dependencies": [{
"field": "search",
"value": "true"
},
{
"field": "searchMode",
"value": "integrated"
}]
},

{
"name": "shareFacebook",
Expand Down
45 changes: 36 additions & 9 deletions app/default-files/default-themes/simple/partials/top.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,42 @@
<div class="search">
<div class="search__overlay js-search-overlay">
<div class="search__overlay-inner">
<form action="{{@website.searchUrl}}" class="search__form">
<input
class="search__input js-search-input"
type="search"
name="{{@config.custom.searchParam}}"
placeholder="{{ translate 'search.placeholder' }}"
aria-label="{{ translate 'search.placeholder' }}"
autofocus="autofocus"/>
</form>
{{#checkIf @config.custom.searchMode '===' "external"}}
<form action="{{@config.custom.searchServer}}" class="search__form" method="{{@config.custom.searchMethod}}" {{#if @config.custom.searchTab}}target="_blank"{{/if}} {{#if @config.custom.searchForceWebsiteResults}}onsubmit="configInputSubmit();"{{/if}}>
{{#if @config.custom.searchForceWebsiteResults}}
<input
id="search_input"
class="search__input js-search-input"
type="search"
placeholder="{{ translate 'search.placeholder' }}"
aria-label="{{ translate 'search.placeholder' }}"
autofocus="autofocus"/>
<input
id="search_go"
type="hidden"
name="{{@config.custom.searchParam}}"/>
{{else}}
<input
class="search__input js-search-input"
type="search"
name="{{@config.custom.searchParam}}"
placeholder="{{ translate 'search.placeholder' }}"
aria-label="{{ translate 'search.placeholder' }}"
autofocus="autofocus"/>
{{/if}}
</form>
{{#if @config.custom.searchForceWebsiteResults}}<script>function configInputSubmit(){document.getElementById('search_go').value='site:'+window.location.hostname+' '+document.getElementById('search_input').value;return true;}</script>{{/if}}
{{else}}
<form action="{{@website.searchUrl}}" class="search__form" {{#if @config.custom.searchTab}}target="_blank"{{/if}}>
<input
class="search__input js-search-input"
type="search"
name="{{@config.custom.searchParam}}"
placeholder="{{ translate 'search.placeholder' }}"
aria-label="{{ translate 'search.placeholder' }}"
autofocus="autofocus"/>
</form>
{{/checkIf}}
<button class="search__close js-search-close" aria-label="{{ translate 'search.close' }}">
{{ translate 'search.close' }}
</button>
Expand Down