All Projects → clarketm → Hugo Elasticsearch

clarketm / Hugo Elasticsearch

Licence: apache-2.0
Generate Elasticsearch indexes for Hugo static sites by parsing front matter

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Hugo Elasticsearch

Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+2115.79%)
Mutual labels:  command-line-tool, cli, yaml, toml
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+32426.32%)
Mutual labels:  cli, yaml, toml
Cli
A simple, fast, and fun package for building command line apps in Go
Stars: ✭ 16,995 (+89347.37%)
Mutual labels:  cli, yaml, toml
Jinja2 Cli
CLI for Jinja2
Stars: ✭ 302 (+1489.47%)
Mutual labels:  cli, yaml, toml
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+9415.79%)
Mutual labels:  command-line-tool, yaml, toml
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+3894.74%)
Mutual labels:  cli, yaml, toml
Transity
Keep track of your 💵, 🕘, 🐖, 🐄, 🍻 on your command line
Stars: ✭ 528 (+2678.95%)
Mutual labels:  command-line-tool, cli
Ttyplot
a realtime plotting utility for terminal/console with data input from stdin
Stars: ✭ 532 (+2700%)
Mutual labels:  command-line-tool, cli
Initior
A command line application that let's you initialize your new projects the right way, replaces npm and yarn's init 🎆
Stars: ✭ 17 (-10.53%)
Mutual labels:  command-line-tool, cli
Dev Setup
macOS development environment setup: Easy-to-understand instructions with automated setup scripts for developer tools like Vim, Sublime Text, Bash, iTerm, Python data analysis, Spark, Hadoop MapReduce, AWS, Heroku, JavaScript web development, Android development, common data stores, and dev-based OS X defaults.
Stars: ✭ 5,590 (+29321.05%)
Mutual labels:  cli, elasticsearch
Es2csv
Export from an Elasticsearch into a CSV file
Stars: ✭ 465 (+2347.37%)
Mutual labels:  cli, elasticsearch
Hypopg
Hypothetical Indexes for PostgreSQL
Stars: ✭ 594 (+3026.32%)
Mutual labels:  index, indexing
Sultan
Sultan: Command and Rule over your Shell
Stars: ✭ 625 (+3189.47%)
Mutual labels:  command-line-tool, cli
Cbt
CBT - fun, fast, intuitive, compositional, statically checked builds written in Scala
Stars: ✭ 489 (+2473.68%)
Mutual labels:  command-line-tool, cli
K2tf
Kubernetes YAML to Terraform HCL converter
Stars: ✭ 477 (+2410.53%)
Mutual labels:  command-line-tool, yaml
Cli
A command-line interface for Hetzner Cloud
Stars: ✭ 542 (+2752.63%)
Mutual labels:  command-line-tool, cli
Node.cli Progress
⌛️ easy to use progress-bar for command-line/terminal applications
Stars: ✭ 466 (+2352.63%)
Mutual labels:  command-line-tool, cli
Elki
ELKI Data Mining Toolkit
Stars: ✭ 613 (+3126.32%)
Mutual labels:  index, indexing
Wbot
A simple Web based BOT for WhatsApp™ in NodeJS 😜. Working as of 📅 Feb 14th, 2020
Stars: ✭ 638 (+3257.89%)
Mutual labels:  command-line-tool, cli
Ripgrep
ripgrep recursively searches directories for a regex pattern while respecting your gitignore
Stars: ✭ 28,564 (+150236.84%)
Mutual labels:  command-line-tool, cli

Hugo-Elasticsearch (HES)

npm-badge codacy-badge circleci-badge

Generate Elasticsearch indexes for Hugo static sites by parsing front matter.



Installation

Install with npm

$ npm install hugo-elasticsearch

Demo

usage demo

Usage

CLI

NAME:
    hugo-elasticsearch
    hes (alias)

SYNOPSIS:
    hes [ opts... ]

DESCRIPTION:
    Generate Elasticsearch indexes from Hugo front matter.

OPTIONS:
    -i, --input path            Input path.                         (default: "content/**")
    -o, --output path           Output path.                        (default: "public/elasticsearch.json")
    -l, --language lang         Language [toml | yaml].             (default: "toml")
    -d, --delimiter delim       Delimiter [toml: +++ | yaml: ---].  (optional)
    -n, --name name             Index name.                         (optional)

Long form
$ hugo-elasticsearch \
 --input "content/**" \
 --output "public/elasticsearch.json" \
 --language "toml" \
 --delimiter "+++" \
 --index-name "posts"
Short form
$ hes \
 -i "content/**" \
 -o "public/elasticsearch.json" \
 -l "toml" \
 -d "+++" \
 -n "posts"

NPM Scripts

...
"scripts": {
  "index": "hes -i 'content/**' -o 'public/elasticsearch.json'"
  "index:toml": "hes -i 'content/toml/**' -o 'public/toml/elasticsearch.json' -l 'toml' -d '+++'"
  "index:yaml": "hes -i 'content/yaml/**' -o 'public/yaml/elasticsearch.json' -l 'yaml' -d '---'"
},
...

API

const hes = require('hugo-elasticsearch');

const Indexer = new hes({
  input: 'content/blog/**',
  output: 'public/static/elasticsearch.json',
  language: 'yaml',
  delimiter: '---',
  indexName: 'posts'
});

// Create index
Indexer.index()

// Setters
Indexer.setInput('content/blog/**');
Indexer.setOutput('public/static/elasticsearch.json');
Indexer.setLanguage('yaml');
Indexer.setDelimiter('---');
Indexer.setIndexName('posts');

Example

1. Create a directory named content.

$ mkdir 'content'

2. Create a markdown file with toml front matter in a file named content/test-toml.md.

$ cat > 'content/test-toml.md' <<EOF
+++
title = "Sample title"
description = "Sample description"
tags = [ "tag1" ]
+++

# Sample content header
Sample content body

EOF

3. Generate a newline delimited json file for indexing in Elasticsearch and output it to a file named public/elasticsearch.json.

$ hes -i 'content/**' -o 'public/elasticsearch.json'

4. Bulk upload your json file to a running Elasticsearch instance.

cURL

$ HOST="localhost"
$ PORT="9200"
$ INDEX="index"
$ TYPE="type"

$ curl \
  -H "Content-Type: application/x-ndjson" \
  -XPOST "$HOST:$PORT/$INDEX/$TYPE/_bulk" \
  --data-binary "@./public/elasticsearch.json"
{
  "took": 137,
  "errors": false,
  "items": [
    ...
  ]
}

JavaScript

const Elastic = require("elasticsearch");
const ndjson = require("ndjson");
const fs = require("fs");

const client = new Elastic.Client({host: 'localhost:9200'});

const fetchBulkJson = () => {
    return new Promise((resolve, reject) => {
      let lines = [];

      fs.createReadStream("./public/elasticsearch.json")
        .pipe(ndjson.parse())
        .on("data", line => lines.push(line))
        .on("end", () => resolve(lines))
        .on("error", err => reject(err));
    });
};

// Perform the bulk index operations in a single API call.
const bulkUpload = async () => {
    const json = await this.fetchBulkJson();
    return await client.bulk({ body: json });
};

Java, Python, Ruby, ...

Although the bulk upload examples above are only for cUrl and JavaScript, this format will work seamlessly with any one of the numerous Elasticsearch clients.

5. You content is now successfully indexed in Elasticsearch 👍. Happy elastic searching!

Refer to the content directory in the root of this project for examples of both yaml and toml content (i.e. .md files).

Refer to the public directory in the root of this project for examples of ndjson files (i.e. Elasticsearch index files) generated from both yaml and toml content.

Sites using hugo-elasticsearch

License

Apache-2.0 © Travis Clarke

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].