{"id":16641837,"url":"https://github.com/samthor/redirects-yaml","last_synced_at":"2026-04-21T17:32:33.827Z","repository":{"id":66115187,"uuid":"318128346","full_name":"samthor/redirects-yaml","owner":"samthor","description":"Helps you define redirects in a YAML file","archived":false,"fork":false,"pushed_at":"2022-06-30T23:14:58.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-18T15:52:53.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/samthor.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-03T08:40:59.000Z","updated_at":"2023-10-08T08:14:07.000Z","dependencies_parsed_at":"2023-02-20T18:01:01.534Z","dependency_job_id":null,"html_url":"https://github.com/samthor/redirects-yaml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fredirects-yaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fredirects-yaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fredirects-yaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fredirects-yaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/redirects-yaml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243164870,"owners_count":20246718,"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":[],"created_at":"2024-10-12T07:48:02.717Z","updated_at":"2026-04-21T17:32:33.775Z","avatar_url":"https://github.com/samthor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a handler for a specific type of redirects config specified in `_redirects.yaml`.\nThe file format looks like:\n\n```yaml\nredirects:\n- from: /page\n  to: /other_page\n- from: /foo/bar/...\n  to: /target/folder/...\n- from: /to_remote\n  to: https://another-domain.com\n```\n\nThis package doesn't depend on a YAML parser, but expects to be passed an array of objects which contain `{from, to}`.\nThis is the default method exported from this package:\n\n```js\nimport buildRedirects from 'redirects-yaml';\n\nconst parsedYaml = ...; // use YAML.parse\nconst handler = buildRedirects(parsedYaml.redirects);\n\nconst matchingOut = handler('/page');      // \"/other_page\"\nconst invalidOut = handler('/not_handled') // null\n```\n\nYou can also use `require()`.\n\n# Try/Else Support\n\nThis package also supports some extended config.\nYou can _try_ possible redirect handlers with an optional default fallback:\n\n```html\nredirects:\n- from: /page/...\n  try:\n  - /foo/...\n  else: /bar/...\n```\n\nIn this case, you'll match URLs under \"/page\".\nThis will then check to see whether the same URL under \"/foo\" exists.\n\n* If it does, a URL under \"/foo\" will be returned.\n\n* If it does not match, then we'll always redirect to the page under \"/bar\".\n\n* ⚠️ External URLs will never pass `try:` checks and won't be passed to your checker.\n\nYou have to specify a `checker` function for `try:` to work:\n\n```js\nconst checker = (pathname, original) =\u003e {\n  // You can check any way you like, but checking whether the file exists makes the most sense.\n  // pathname can be blank (exact match), or it will start with \"/\" and have a longer path.\n  // You MUST ALWAYS use `path.join` to combine it with a real root.\n  const check = path.join('/your/root', pathname);\n  return fs.existsSync(check); // cannot be async\n\n  // If you're on Windows, be sure to control for URL-style slashes \"/\" with your filesystem\n  // which will have \"\\\" slashes.\n};\nconst handler = buildRedirects(parsedYaml.redirects, checker);\n```\n\nNote that the `else:` default fallback is optional.\nIf none of your `try:` candidates pass your checker, this will continue stepping through other redirect options.\n\n# Dependencies\n\nThis has no dependencies. 🍩","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fredirects-yaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fredirects-yaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fredirects-yaml/lists"}