{"id":39397720,"url":"https://github.com/permalinks/static-rewrite","last_synced_at":"2026-01-18T03:20:17.133Z","repository":{"id":57370110,"uuid":"82365334","full_name":"permalinks/static-rewrite","owner":"permalinks","description":"Easily generate destination paths or static URLs by mapping user-friendly patterns to server-side build paths.","archived":false,"fork":false,"pushed_at":"2017-02-18T07:25:26.000Z","size":18,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-02T10:05:07.170Z","etag":null,"topics":["build","dest","filepath","path","permalinks","rewrite","rewrite-urls","tooling"],"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/permalinks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-18T05:57:57.000Z","updated_at":"2020-08-29T14:26:16.000Z","dependencies_parsed_at":"2022-09-26T16:41:04.770Z","dependency_job_id":null,"html_url":"https://github.com/permalinks/static-rewrite","commit_stats":null,"previous_names":["jonschlinkert/static-rewrite"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/permalinks/static-rewrite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permalinks%2Fstatic-rewrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permalinks%2Fstatic-rewrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permalinks%2Fstatic-rewrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permalinks%2Fstatic-rewrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/permalinks","download_url":"https://codeload.github.com/permalinks/static-rewrite/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permalinks%2Fstatic-rewrite/sbom","scorecard":{"id":727997,"data":{"date":"2025-08-11","repo":{"name":"github.com/permalinks/static-rewrite","commit":"b7b3be88fb9ce916f794d45489fc8b8fa89cf728"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 0/8 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T13:27:34.695Z","repository_id":57370110,"created_at":"2025-08-22T13:27:34.695Z","updated_at":"2025-08-22T13:27:34.695Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28528036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["build","dest","filepath","path","permalinks","rewrite","rewrite-urls","tooling"],"created_at":"2026-01-18T03:20:15.093Z","updated_at":"2026-01-18T03:20:17.084Z","avatar_url":"https://github.com/permalinks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# static-rewrite [![NPM version](https://img.shields.io/npm/v/static-rewrite.svg?style=flat)](https://www.npmjs.com/package/static-rewrite) [![NPM monthly downloads](https://img.shields.io/npm/dm/static-rewrite.svg?style=flat)](https://npmjs.org/package/static-rewrite)  [![NPM total downloads](https://img.shields.io/npm/dt/static-rewrite.svg?style=flat)](https://npmjs.org/package/static-rewrite) [![Linux Build Status](https://img.shields.io/travis/permalinks/static-rewrite.svg?style=flat\u0026label=Travis)](https://travis-ci.org/permalinks/static-rewrite)\n\n\u003e Easily generate destination paths or static URLs by mapping user-friendly patterns to server-side build paths.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save static-rewrite\n```\n\n## What does this do?\n\nThis module does something similar to [URL rewriting](#url-rewriting), but for static paths at build-time. The goal is to consistently and easily generate correct destination paths during development, regardless of the source paths.\n\n**Examples**\n\nLet's say we have a blog, with post titled \"How To Create Effective Permalinks\", and we want to:\n\n* automatically write the post to the root of our site\n* use the slugified `title` from front-matter as the folder name (for \"pretty\" permalinks)\n* append `/index.html` to the path (also for \"pretty\" permalinks)\n\nIn other words, we want this source path:\n\n```\nsrc/content/posts/2017-02-14.md\n```\n\nTo be written to a destination path that looks something like:\n\n```\nblog/how-to-create-effective-permalinks/index.html\n```\n\nYou can either manually parse and reformat your destination paths, or use this library with simple rewrite rules.\n\n**Example rewrite rule**\n\nThe following rule(s) will match any files in the `posts` directory, and rewrite the path using the given [structure](https://github.com/jonschlinkert/permalinks#structure).\n\n```js\nrewriter.rule(/posts\\//, 'blog/:slugify(title)/index.html');\n// add extra validation if necessary\nrewriter.rule(/posts\\//, 'blog/:slugify(title)/index.html', function(file) {\n  return file.extname === '.md';\n});\n```\n\n\u003ca name=\"url-rewriting\"\u003e\u003c/a\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eURL rewriting\u003c/strong\u003e\u003c/summary\u003e\nURL rewriting is used for replacing semantic, user-friendly URLs with server-friendly URLs.\n\nFor example, when a user enters a URL like the following to go to a page on wikipedia:\n\n```\nhttps://en.wikipedia.org/wiki/Business\n```\n\nThe URL might be rewritten by wikipedia to something like:\n\n```\nhttps://en.wikipedia.org/w/index.php?title=Business\n```\n\u003c/details\u003e\n\n## Usage\nAdd this library to your JavaScript application with the following line of code:\n\n```js\nvar Rewriter = require('static-rewrite');\n```\n\n## API\n\n### [Rewriter](index.js#L31)\n\nCreate an instance of `Rewriter` with the given `options`.\n\n**Params**\n\n* `options` **{Object}**\n\n**Example**\n\n```js\nvar rewriter = new Rewriter()\n  .rule(/posts/, 'blog/:stem/index.html')\n  .rule(/docs/, 'docs/:stem/index.html')\n\nconsole.log(rewriter.rewrite({path: 'content/posts/first-post.md'}));\n//=\u003e 'blog/first-post/index.html'\n\nconsole.log(rewriter.rewrite({path: 'content/posts/other-post.md'}));\n//=\u003e 'blog/other-post/index.html'\n\nconsole.log(rewriter.rewrite({path: 'content/docs/api.md'}));\n//=\u003e 'docs/api/index.html'\n```\n\n### [.rule](index.js#L70)\n\nRegister a rewrite rule with a `regex` to use for matching paths, a `structure` to use for the replacement patter, and an optional validation `fn` to supplement the regex when matching.\n\n**Params**\n\n* `regex` **{RegExp}**\n* `structure` **{String}**\n* `fn` **{Function}**: Optionally pass a function to do further validation on the file (return `false` if the rule shouldn't be used) and/or to update the context to be used for resolving placeholders in the rule `structure`.\n* `returns` **{Object}**: Returns the Rewriter instance for chaining.\n\n**Example**\n\n```js\nrewriter.rule(':folder/([^\\\\/]+)/(.*)', ':dirname/:foo/:stem.html');\nrewriter.rule(/([^\\\\/]+)\\/*\\.hbs$/, ':dirname/:foo/:stem.html');\nrewriter.rule(/\\.hbs$/, ':dirname/:stem.html');\nrewriter.rule(/\\.md$/, 'blog/:stem/index.html', function(file) {\n  return file.dirname !== 'foo/bar';\n});\n```\n\n### [.rewrite](index.js#L86)\n\nRun rewrite [rules](#rule) on the given `file`. If a rule matches\nthe file, the `file.path` will be rewritten using `locals`, and values\nfrom the `file` and `file.data`.\n\n**Params**\n\n* `file` **{Object}**\n* `locals` **{Object}**\n* `returns` **{String}**: Returns the formatted path or the original `file.path` if no rewrite rules match the file.\n\n### [.match](index.js#L123)\n\nCalls `RegExp.exec()` on `file.path`, using the regex from the given rewrite `rule`. If the file matches, the match arguments are returned, otherwise `null`.\n\n**Params**\n\n* `rule` **{Object}**\n* `file` **{Object}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar fileA = new File({path: 'blog/drafts/about.hbs'});\nvar fileB = new File({path: 'blog/content/about.hbs'});\n\nvar ruleA = new rewriter.Rule(/blog\\//, ':stem/index.html');\nvar ruleB = new rewriter.Rule(/blog\\//, ':stem/index.html', function(file) {\n  return !/drafts/.test(file.path);\n});\n\nconsole.log(rewriter.match(ruleA, fileA)); //\u003c= true\nconsole.log(rewriter.match(ruleB, fileA)); //\u003c= false\n\nconsole.log(rewriter.match(ruleA, fileB)); //\u003c= true\nconsole.log(rewriter.match(ruleB, fileB)); //\u003c= true\n```\n\n### [Rule](index.js#L169)\n\nCreate a new `Rule` with the given `pattern`, `structure` and optional function for validating or adding data to the context\n\n**Params**\n\n* `pattern` **{String}**\n* `structure` **{String}**\n* `fn` **{Function}**\n\n**Example**\n\n```js\nvar rule = new Rule(/posts/, 'blog/:stem/index.html');\nvar rule = new Rule(/posts/, 'blog/:stem/index.html', function(file) {\n  return file.extname !== '.foo';\n});\nvar rule = new Rule(/posts/, 'blog/:stem/index.html', function(file, params) {\n  file.data = Object.assign({}, file.data, params);\n});\n```\n\n## About\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).\nMIT\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 18, 2017._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermalinks%2Fstatic-rewrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermalinks%2Fstatic-rewrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermalinks%2Fstatic-rewrite/lists"}