{"id":20551574,"url":"https://github.com/clarketm/hugo-elasticsearch","last_synced_at":"2025-06-21T06:41:26.225Z","repository":{"id":86955306,"uuid":"123996461","full_name":"clarketm/hugo-elasticsearch","owner":"clarketm","description":"Generate Elasticsearch indexes for Hugo static sites by parsing front matter","archived":false,"fork":false,"pushed_at":"2019-10-01T01:22:50.000Z","size":4323,"stargazers_count":30,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T11:09:58.958Z","etag":null,"topics":["cli","command-line-tool","elasticsearch","hugo","index","indexer","indexing","indexing-engine","toml","yaml"],"latest_commit_sha":null,"homepage":"https://blog.travismclarke.com/project/hugo-elasticsearch/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clarketm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-06T00:24:34.000Z","updated_at":"2024-04-13T09:36:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"96880106-efc4-4e61-be03-a2249328f16b","html_url":"https://github.com/clarketm/hugo-elasticsearch","commit_stats":{"total_commits":76,"total_committers":2,"mean_commits":38.0,"dds":"0.13157894736842102","last_synced_commit":"2091c0d90ffbe3eef4634e4b4a4cfbf89b2eef7f"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/clarketm/hugo-elasticsearch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarketm%2Fhugo-elasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarketm%2Fhugo-elasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarketm%2Fhugo-elasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarketm%2Fhugo-elasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarketm","download_url":"https://codeload.github.com/clarketm/hugo-elasticsearch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarketm%2Fhugo-elasticsearch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261080113,"owners_count":23106564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line-tool","elasticsearch","hugo","index","indexer","indexing","indexing-engine","toml","yaml"],"created_at":"2024-11-16T02:32:16.251Z","updated_at":"2025-06-21T06:41:21.202Z","avatar_url":"https://github.com/clarketm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Hugo-Elasticsearch (HES)](https://blog.travismclarke.com/project/hugo-elasticsearch/)\n\n[![npm-badge](https://img.shields.io/npm/v/hugo-elasticsearch.svg)](https://www.npmjs.com/package/hugo-elasticsearch)\n[![codacy-badge](https://api.codacy.com/project/badge/Grade/1ce2505fd16c4e5ab284c7b36b666a08)](https://www.codacy.com/app/clarketm/hugo-elasticsearch?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=clarketm/hugo-elasticsearch\u0026amp;utm_campaign=Badge_Grade)\n[![circleci-badge](https://circleci.com/gh/clarketm/hugo-elasticsearch.svg?style=shield)](https://circleci.com/gh/clarketm/hugo-elasticsearch)\n\nGenerate [Elasticsearch](https://www.elastic.co/products/elasticsearch) indexes for [Hugo](https://gohugo.io/) static sites by parsing front matter.\n\n\u003cbr\u003e\n\u003cbr\u003e\n\u003ca href=\"https://blog.travismclarke.com/project/hugo-elasticsearch/\"\u003e\n  \u003cp align=\"center\"\u003e\u003cimg width=\"40%\" src=\"/hero.png\" /\u003e\u003c/p\u003e\n\u003c/a\u003e\n\n## Installation\n\n### Install with npm\n```bash\n$ npm install hugo-elasticsearch\n```\n\n## Demo\n\n![usage demo](https://github.com/clarketm/hugo-elasticsearch/blob/master/usage.gif)\n\n## Usage\n\n### CLI\n```bash\n\nNAME:\n    hugo-elasticsearch\n    hes (alias)\n\nSYNOPSIS:\n    hes [ opts... ]\n\nDESCRIPTION:\n    Generate Elasticsearch indexes from Hugo front matter.\n\nOPTIONS:\n    -i, --input path            Input path.                         (default: \"content/**\")\n    -o, --output path           Output path.                        (default: \"public/elasticsearch.json\")\n    -l, --language lang         Language [toml | yaml].             (default: \"toml\")\n    -d, --delimiter delim       Delimiter [toml: +++ | yaml: ---].  (optional)\n    -n, --name name             Index name.                         (optional)\n\n```\n\n##### Long form\n```bash\n$ hugo-elasticsearch \\\n --input \"content/**\" \\\n --output \"public/elasticsearch.json\" \\\n --language \"toml\" \\\n --delimiter \"+++\" \\\n --index-name \"posts\"\n```\n\n##### Short form\n```bash\n$ hes \\\n -i \"content/**\" \\\n -o \"public/elasticsearch.json\" \\\n -l \"toml\" \\\n -d \"+++\" \\\n -n \"posts\"\n```\n\n### NPM Scripts\n```javascript\n...\n\"scripts\": {\n  \"index\": \"hes -i 'content/**' -o 'public/elasticsearch.json'\"\n  \"index:toml\": \"hes -i 'content/toml/**' -o 'public/toml/elasticsearch.json' -l 'toml' -d '+++'\"\n  \"index:yaml\": \"hes -i 'content/yaml/**' -o 'public/yaml/elasticsearch.json' -l 'yaml' -d '---'\"\n},\n...\n```\n\n\n### API\n```javascript\nconst hes = require('hugo-elasticsearch');\n\nconst Indexer = new hes({\n  input: 'content/blog/**',\n  output: 'public/static/elasticsearch.json',\n  language: 'yaml',\n  delimiter: '---',\n  indexName: 'posts'\n});\n\n// Create index\nIndexer.index()\n\n// Setters\nIndexer.setInput('content/blog/**');\nIndexer.setOutput('public/static/elasticsearch.json');\nIndexer.setLanguage('yaml');\nIndexer.setDelimiter('---');\nIndexer.setIndexName('posts');\n```\n\n## Example\n\n#### 1. Create a directory named `content`.\n```bash\n$ mkdir 'content'\n```\n\n#### 2. Create a markdown file with `toml` front matter in a file named `content/test-toml.md`.\n```markdown\n$ cat \u003e 'content/test-toml.md' \u003c\u003cEOF\n+++\ntitle = \"Sample title\"\ndescription = \"Sample description\"\ntags = [ \"tag1\" ]\n+++\n\n# Sample content header\nSample content body\n\nEOF\n```\n\n#### 3. Generate a newline delimited json file for indexing in Elasticsearch and output it to a file named `public/elasticsearch.json`.\n```bash\n$ hes -i 'content/**' -o 'public/elasticsearch.json'\n```\n\n#### 4. [Bulk](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html) upload your json file to a running Elasticsearch instance.\n\n**[cURL](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)**\n```bash\n$ HOST=\"localhost\"\n$ PORT=\"9200\"\n$ INDEX=\"index\"\n$ TYPE=\"type\"\n\n$ curl \\\n  -H \"Content-Type: application/x-ndjson\" \\\n  -XPOST \"$HOST:$PORT/$INDEX/$TYPE/_bulk\" \\\n  --data-binary \"@./public/elasticsearch.json\"\n```\n\n```json\n{\n  \"took\": 137,\n  \"errors\": false,\n  \"items\": [\n    ...\n  ]\n}\n```\n\n**[JavaScript](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-bulk)**\n```js\nconst Elastic = require(\"elasticsearch\");\nconst ndjson = require(\"ndjson\");\nconst fs = require(\"fs\");\n\nconst client = new Elastic.Client({host: 'localhost:9200'});\n\nconst fetchBulkJson = () =\u003e {\n    return new Promise((resolve, reject) =\u003e {\n      let lines = [];\n\n      fs.createReadStream(\"./public/elasticsearch.json\")\n        .pipe(ndjson.parse())\n        .on(\"data\", line =\u003e lines.push(line))\n        .on(\"end\", () =\u003e resolve(lines))\n        .on(\"error\", err =\u003e reject(err));\n    });\n};\n\n// Perform the bulk index operations in a single API call.\nconst bulkUpload = async () =\u003e {\n    const json = await this.fetchBulkJson();\n    return await client.bulk({ body: json });\n};\n```\n\n**[Java](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html), [Python](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/index.html), [Ruby](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html), ...**\n\u003e 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](https://www.elastic.co/guide/en/elasticsearch/client/index.html).\n\n#### 5. You content is now successfully indexed in Elasticsearch 👍. Happy elastic searching!\n\n\u003e Refer to the [`content`](content) directory in the root of *this* project for examples of both *yaml* and *toml* content (i.e. `.md` files).\n\n\u003e Refer to the [`public`](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.\n\n## Sites using hugo-elasticsearch\n* https://blog.travismclarke.com/\n\n## License\nApache-2.0 © [Travis Clarke](https://www.travismclarke.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarketm%2Fhugo-elasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarketm%2Fhugo-elasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarketm%2Fhugo-elasticsearch/lists"}