{"id":24383474,"url":"https://github.com/firstandthird/hapi-generate-sitemap","last_synced_at":"2025-12-25T09:10:46.831Z","repository":{"id":54123527,"uuid":"107594096","full_name":"firstandthird/hapi-generate-sitemap","owner":"firstandthird","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-09T02:18:05.000Z","size":66,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-04T09:40:25.225Z","etag":null,"topics":["hapi-plugin","hapi-v17","has-tests","needs-coverage"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstandthird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-19T20:17:15.000Z","updated_at":"2025-01-31T18:14:58.000Z","dependencies_parsed_at":"2022-08-13T07:01:01.499Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/hapi-generate-sitemap","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-generate-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-generate-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-generate-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-generate-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/hapi-generate-sitemap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243259043,"owners_count":20262385,"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":["hapi-plugin","hapi-v17","has-tests","needs-coverage"],"created_at":"2025-01-19T10:14:34.098Z","updated_at":"2025-12-25T09:10:41.786Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","readme":"# hapi-generate-sitemap\n\nhapi-generate-sitemap is a simple [hapi](https://hapi.dev/) plugin that automates generating and serving your sitemap.html / sitemap.xml files.\n\n## Install\n\n```\nnpm install hapi-generate-sitemap\n```\n\n## Basic Usage\n\n```js\n\nawait server.register(require('hapi-generate-sitemap'), {});\n\nserver.route({\n  method: 'get',\n  path: '/foopath1',\n  config: {\n    plugins: {\n      sitemap: true\n    }\n  },\n  handler(request, h) {\n    return { success: true };\n  }\n});\n```\n\nNow GET _/sitemap.html_ and it will return:\n\n```\n\u003cul\u003e\n \u003cli\u003e\u003ca href=\"http://localhost:8080/foopath\"\u003ehttp://localhost:8080/foopath\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nGET _/sitemap.xml_ will return:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttp://localhost:8080/foopath\u003c/loc\u003e\n  \u003c/url\u003e\n\u003c/xml\u003e\n```\n\nand GET _/sitemap.json_ will give:\n```js\n[{\n  path: '/foopath',\n}]\n```\n\nNote that you have to have _sitemap: true_ in your route config, or hapi-generate-sitemap will assume you do not want to show that route.\n\n## Advanced Usage\n\nhapi-generate-sitemap also supports populating a sitemap _template_ so you can customize the appearance of your HTML sitemap and render it with your view engine:\n\nSay you are using [handlebars](https://handlebarsjs.com/) for rendering and you have a template called _sitemap_template.html_:\n\n```html\n\u003cstyle\u003e\na {\n  color: green;\n}\n\u003c/style\u003e\n\n\u003ch1\u003eMy Site Looks Like:\u003c/h1\u003e\n{{#each sitemap}}\n    \u003ca href=\"{{url}}\"\u003e{{url}}\u003c/a\u003e\n{{/each}}\n```\n\nYou can have hapi-generate-sitemap use this template:\n\n```js\nserver.views({\n  engines: { html: require('handlebars') },\n  relativeTo: __dirname,\n  path: 'views'\n});\n\nawait server.register([\n  {\n    // hapi's template rendering library:\n    plugin: require('vision'),\n  },\n  {\n    plugin: require('hapi-generate-sitemap'),\n    options: {\n      htmlView: 'sitemap_template'\n    }\n  },\n]);\n```\n\nNow when you GET _/sitemap.html_ the server will pass the  context to _sitemap_template.html_:\n\n```js\n{\n  sitemap: [\n   {\n     url: 'http://localhost:8080/foopath',\n     section: 'none',\n     lastmod: '2005-01-01',\n     changefreq: 'monthly',\n     priority: 0.8\n   }\n ]\n}\n```\n\nAnd you will get back something like:\n\n```html\n\u003cstyle\u003e\na {\n  color: green;\n}\n\u003c/style\u003e\n\n\u003ch1\u003eMy Site Looks Like:\u003c/h1\u003e\n\u003ca href=\"http://localhost:8080/foopath\"\u003e\n  http://localhost:8080/foopath\n\u003c/a\u003e\n```\n\n## Query Options\n\nYou can pass these options as query parameters when you HTTP GET the sitemap:\n\n- __meta__\n\nPass a positive value to this to include additional route metadata.  For example, if you have a route like this:\n```javascript\nserver.route({\n  method: 'get',\n  path: '/path1',\n  config: {\n    plugins: {\n      sitemap: {\n        section: 'Interviews',\n        lastmod: '2005-01-01',\n        changefreq: 'monthly',\n        priority: 0.8,\n      }\n    }\n  },\n  handler(request, h) {\n    return { success: true };\n  }\n});\n```\n\n GET _sitemap.json?meta=1_ will return:\n```javascript\n[{\n  path: '/path1',\n  section: 'Interviews',\n  lastmod: '2005-01-01',\n  priority: 0.8,\n  changefreq: 'monthly',\n}]\n```\n\n- __all__\n\nBy default hapi-generate-sitemap will skip routes that don't have '_sitemap: true_' specified in their route config.  Passing the _all_ query parameter will ignore this and list all routes.\n\n- __limit__\n\nLimits the number of entries to show, eg _?limit=10_ will only show ten entries.\n\n## Plugin Options\n\nPass these options when you _register()_ the plugin with hapi:\n\n- __videoPages__\n\n  A function which returns an array of videos on your site.  Each video should be returned in the format:\n\n  ```js\n  {\n    url: '/the-video-url',\n    video: {\n      title: 'a car video',\n      thumbnail_loc: 'car.png',\n      description: 'description of a car video',\n      content_loc: 'http://youtube.com/1234'\n    }  \n  ```\n\n  and the video data will be listed as:\n  ```html\n  \u003cvideo:video\u003e\n    \u003cvideo:title\u003ea car video\u003c/video:title\u003e\n    \u003cvideo:description\u003edescription of a car video\u003c/video:description\u003e\n    \u003cvideo:thumbnail_loc\u003ecar.png\u003c/video:thumbnail_loc\u003e\n    \u003cvideo:content_loc\u003ehttp://youtube.com/1234\u003c/video:content_loc\u003e\n  \u003c/video:video\u003e\n  ```\n\n- __htmlView__\n\n  Name of the template to use for rendering the HTML version of the sitemap, will use the built-in template if not specified.     \n\n- __forceHttps__\n\n  Forces each listed route to be 'https', default is false.\n\n- __excludeTags__\n\n  An array listing tags to be ignored. Routes containing one or more of these tags will not appear in the sitemap.\n\n- __excludeUrls__\n\n  An array of urls to be ignored.  These routes wiill not appear in the sitemap.\n\n- __additionalRoutes__\n\n  A function that returns a list of any additional routes you want to be listed on your sitemap.\n\n- __dynamicRoutes__\n\n  hapi allows you to specify routes that contain dynamic path parameters, for example _/user/{userName}_  will match both _/user/roberto_ and _/user/jin_. Since hapi does not know all the possible path options for dynamic parameters, you can pass a __dynamicRoutes__ function to manage these. __dynamicRoutes__ will take in the current _path_ and the _request_ (for access to query values) as parameters and should return a list of routes that mapping for the dynamic route like so:\n  ```js\n  function dynamicRoutes(path, request) {\n    const routes = {\n      '/path/{param}': [\n        {\n          path: '/path/param1',\n          lastmod: '2005-01-01',\n          changefreq: 'monthly',\n          priority: 0.8,\n        },\n        '/path/param2',\n        '/path/param3'\n      ]\n    };\n    return (routes[path]) ? routes[path] : [];\n  ```    \n\n- __getRouteMetaData__\n\n  You can also pass a __getRouteMetaData__ function to augment or override the path information contained by the server.  The current page data will be passed to the function.  If the function returns a false value then there is no effect.  If the function returns an object, it will be combined with the existing _page_ object, matching values that also exist in _page_ will be over-written by the metadata:  \n\n```js\ngetRouteMetaData(page) {\n  if (page.path === '/path1') {\n    return {\n      lastmod: '2005-01-01',\n      priority: 0.8,\n    };\n  }\n  return false;\n}\n```\n\n- __endpoint__\n\n  The root path where you can get the sitemap, default is \"_/sitemap_\".\n\n\n- __logRequest__\n\n  Specifies whether to log each request for the sitemap, default is false.\n\n- __maxPerPage__\n\n  Max number of route entries to return per page, default is 1000.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-generate-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fhapi-generate-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-generate-sitemap/lists"}