Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
hugo-elasticsearch
Advanced tools
Generate elasticsearch indices for Hugo static sites by parsing front matter.
Generate Elasticsearch indexes for Hugo static sites by parsing front matter.
$ npm install hugo-elasticsearch
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)
$ hugo-elasticsearch \
--input "content/**" \
--output "public/elasticsearch.json" \
--language "toml" \
--delimiter "+++" \
--index-name "posts"
$ hes \
-i "content/**" \
-o "public/elasticsearch.json" \
-l "toml" \
-d "+++" \
-n "posts"
...
"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 '---'"
},
...
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');
content
.$ mkdir 'content'
toml
front matter in a file named content/test-toml.md
.$ echo '+++
title = "Sample title"
description = "Sample description"
tags = [ "tag1" ]
+++
# Sample content header
Sample content body
' > 'content/test-toml.md'
public/elasticsearch.json
.$ hes -i 'content/**' -o 'public/elasticsearch.json'
$ 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": [
...
]
}
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 });
};
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.
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.
Apache-2.0 © Travis Clarke
FAQs
Generate elasticsearch indices for Hugo static sites by parsing front matter.
The npm package hugo-elasticsearch receives a total of 12 weekly downloads. As such, hugo-elasticsearch popularity was classified as not popular.
We found that hugo-elasticsearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.