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

Provide example usage for other static site generatos #10

Closed
1 of 3 tasks
mre opened this issue Apr 29, 2019 · 11 comments
Closed
1 of 3 tasks

Provide example usage for other static site generatos #10

mre opened this issue Apr 29, 2019 · 11 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@mre
Copy link
Member

mre commented Apr 29, 2019

We need to add some usage examples for

  • Jekyll
  • Hugo
  • Cobalt

For the most part, this means showing how to create an index.json as shown in /fixtures/index.json from this repo.

For example, I'm using the following template file for zola:

{% set section = get_section(path="_index.md") %}

[
{%- for post in section.pages -%}
{
"title": {{ post.title | safe | striptags | json_encode }},
"url": {{ post.permalink | safe | json_encode }},
"body": {{ post.content | safe | striptags | json_encode }}
}{% if not loop.last %},{% endif %}
{%- endfor -%}
]

If someone wants to tackle this, feel free to add a comment here so that others know you're working on this. You can also create a pull request straight away.

@mre mre added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Apr 29, 2019
@mre
Copy link
Member Author

mre commented Apr 30, 2019

@machbio
Copy link

machbio commented Jun 10, 2020

  • Pelican

Pelican

Pelican has a plugin called Tipue Search (https://github.com/getpelican/pelican-plugins/tree/master/tipue_search) which uses a javascript variable json similar to the tinysearch - it would be interesting to see if tinysearch is scalable for a medium sized blog

@Lusitaniae
Copy link

Lusitaniae commented Jun 10, 2020

Hugo - Seems they usually build external tools to generate search indexes, see https://gohugo.io/tools/search/

To do it natively you build a template and adding it as "export" format

cat layouts/_default/baseof.json.json

[
	{{ block "response" .}}{{ end }}
]

cat layouts/_default/list.json.json

{{ define "response" }}
[
    {{ range $index, $e := .Data.Pages }}
    {{ if $index }}, {{ end }}{{ .Render "item" }}
    {{ end }}
]
{{ end }}

cat layouts/_default/item.json.json

	{
	    "title": "{{ .Title }}",
	    "url" : "{{ .Permalink }}",
	    "body" : "{{  .PlainWords  }}"
	}

cat config.toml


...

[outputs]
    home = ["json"] # Everything



File will be in public/index.json

See https://forestry.io/blog/build-a-json-api-with-hugo/

@mre
Copy link
Member Author

mre commented Jun 11, 2020

Thanks @Lusitaniae,
added your tutorial at https://github.com/mre/tinysearch/blob/master/howto/hugo.md.

@mre
Copy link
Member Author

mre commented Jun 11, 2020

Anyone wants to tackle Jekyll or Pelican?

@lord-re
Copy link
Contributor

lord-re commented Jul 1, 2020

To implement it in Hugo, you can have a simpler setup :

layout/_default/list.json.json

[
{{ range $index , $e := .Site.RegularPages }}{{ if $index }}, {{end}}{{ dict "title" .Title "url" .Permalink "body" .Plain | jsonify }}{{end}}
]

and config.toml

[outputs]
home = ["html","json","rss"]

( if you only put json, you won't build your site and your rss anymore).

It's a bit simpler and doesn't break the site.

@mre
Copy link
Member Author

mre commented Jul 1, 2020

Nice @lord-re. Much appreciated!
Can you edit the file here and create a pull request?
I'd merge it on the spot.

@Ninjani
Copy link
Contributor

Ninjani commented Aug 11, 2020

Hello! Figured this out for Pelican to add to our website.

You need a templates/json.html file with:

[
{%- for article in articles -%}
{% if article.status != "draft" %}
{
"title": {{ article.title | striptags | tojson | safe }},
"url": {{ article.url | tojson | safe }},
"body": {{ article.content | striptags | tojson | safe }}
}{% if not loop.last %},{% endif %}
{% endif %}
{%- endfor -%}
]

and a json.md file in your content/pages folder with

Title: JSON
Template: json
Slug: json

Then, after running pelican content, tinysearch --path output output/pages/json.html builds the index.

Shall I make a PR?

@mre
Copy link
Member Author

mre commented Aug 11, 2020

Nice! PR would be very welcome. 😊

@dertuxmalwieder
Copy link

To implement it in Hugo, you can have a simpler setup

Doing that generates a public/index.json which contains an empty list. Why?

@mre mre pinned this issue Mar 4, 2023
@mre
Copy link
Member Author

mre commented Jul 24, 2023

Sorry for the late response. I don't know what might cause this.
Maybe @lord-re has an idea. If so, please post below and we can reopen.

@mre mre closed this as completed Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants