getnikola / nikola-themes

Themes for Nikola
https://themes.getnikola.com/
71 stars 51 forks source link

Zen does not show search_form #166

Closed hygorxaraujo closed 5 years ago

hygorxaraujo commented 5 years ago

When I try to configure the search form in conf.py I get the following error:

Traceback (most recent call last):
  File "python3.7/site-packages/doit/doit_cmd.py", line 177, in run
    return command.parse_execute(args)
  File "python3.7/site-packages/doit/cmd_base.py", line 127, in parse_execute
    return self.execute(params, args)
  File "python3.7/site-packages/doit/cmd_base.py", line 389, in execute
    self, params, args)
  File "python3.7/site-packages/nikola/__main__.py", line 277, in load_tasks
    self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.'))
  File "python3.7/site-packages/doit/loader.py", line 313, in generate_tasks
    for task_dict, x_doc in flat_generator(gen_result, gen_doc):
  File "python3.7/site-packages/doit/loader.py", line 26, in flat_generator
    for item in gen:
  File "python3.7/site-packages/nikola/nikola.py", line 1946, in gen_tasks
    for task in flatten(pluginInfo.plugin_object.gen_tasks()):
  File "python3.7/site-packages/nikola/nikola.py", line 1941, in flatten
    for ft in flatten(t):
  File "python3.7/site-packages/nikola/nikola.py", line 1940, in flatten
    for t in task:
  File "python3.7/site-packages/nikola/plugins/task/taxonomies.py", line 261, in _generate_classification_page_as_list
    task = self.site.generic_post_list_renderer(lang, filtered_posts, output_name, template_name, kw['filters'], context)
  File "python3.7/site-packages/nikola/nikola.py", line 2280, in generic_post_list_renderer
    post_deps_dict=post_deps_dict)
  File "python3.7/site-packages/nikola/nikola.py", line 2177, in generic_renderer
    deps_dict[k] = deps_dict['global'][k](lang)
TypeError: 'str' object is not callable

The setup:

SEARCH_FORM = """
<!-- DuckDuckGo custom search -->
<form method="get" id="search" action="https://duckduckgo.com/"
 class="navbar-form pull-left">
<input type="hidden" name="sites" value="%s">
<input type="hidden" name="k8" value="#444444">
<input type="hidden" name="k9" value="#D51920">
<input type="hidden" name="kt" value="h">
<input type="text" name="q" maxlength="255"
 placeholder="Search&hellip;" class="span2" style="margin-top: 4px;">
<input type="submit" value="DuckDuckGo Search" style="visibility: hidden;">
</form>
<!-- End of custom search -->
""" % SITE_URL

GLOBAL_CONTEXT = {
    'search_form': SEARCH_FORM,
}
Kwpolska commented 5 years ago

search_form is already available in the global context, don’t add it to GLOBAL_CONTEXT manually.

hygorxaraujo commented 5 years ago

Ok, thank you for your reply. I got to this configuration by following a sample conf.py (probably outdated). My real problem is that after setting SEARCH_FORM in conf.py the search form is not showing in my theme. Tried with themes zen and zen-forkawesome.

Kwpolska commented 5 years ago

Which conf.py was it?

SEARCH_FORM needs to be used by the theme. The zen themes might not include it in the default configuration, if that’s the case, you’ll need to manually add ${search_form} in the template in the place where you want it to appear.

hygorxaraujo commented 5 years ago

Sorry, can't find or remember where I saw the conf.py.

From this https://github.com/getnikola/nikola-themes/blob/69deab1c6b2b76c154f9e17fb7ac731a7208e51a/v8/zen/templates/base_header.tmpl#L9 it seems that the search form is used by zen. If I move that piece of code to before ${header.html_navigation_links()} in base.tmpl, the search form is shown, although not properly. https://github.com/getnikola/nikola-themes/blob/69deab1c6b2b76c154f9e17fb7ac731a7208e51a/v8/zen/templates/base.tmpl#L24

search-nikola-zen

Kwpolska commented 5 years ago

Yeah, that’s a bug. The function you’re seeing is not used anywhere. I’ll fix this.

To make the search_form look nice, you will need custom CSS. If you find something that looks good, feel free to contribute this to the zen theme itself.