{"id":24983721,"url":"https://github.com/posthtml/posthtml-base-url","last_synced_at":"2025-04-11T20:52:37.259Z","repository":{"id":38844487,"uuid":"445476731","full_name":"posthtml/posthtml-base-url","owner":"posthtml","description":"Prepend a string to source paths in your HTML.","archived":false,"fork":false,"pushed_at":"2025-04-03T10:53:54.000Z","size":1815,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-11T20:52:27.198Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posthtml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["maizzle"],"patreon":"posthtml","open_collective":"posthtml","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://mailviews.com"]}},"created_at":"2022-01-07T10:05:33.000Z","updated_at":"2025-04-03T10:52:50.000Z","dependencies_parsed_at":"2023-12-04T08:03:56.903Z","dependency_job_id":"ebef5c79-915d-4aa3-91be-b420212ade50","html_url":"https://github.com/posthtml/posthtml-base-url","commit_stats":{"total_commits":179,"total_committers":3,"mean_commits":"59.666666666666664","dds":0.4916201117318436,"last_synced_commit":"ad7489d63e5abf29be2d9b6d4f378924f09321c9"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-base-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-base-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-base-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-base-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-base-url/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480515,"owners_count":21110936,"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":"2025-02-04T09:20:46.039Z","updated_at":"2025-04-11T20:52:37.227Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"150\" height=\"150\" alt=\"PostHTML\" src=\"https://posthtml.github.io/posthtml/logo.svg\"\u003e\n  \u003ch1\u003eBase URL\u003c/h1\u003e\n  \u003cp\u003ePrepend a string to source paths in your HTML\u003c/p\u003e\n\n  [![Version][npm-version-shield]][npm]\n  [![Build][github-ci-shield]][github-ci]\n  [![License][license-shield]][license]\n  [![Downloads][npm-stats-shield]][npm-stats]\n\u003c/div\u003e\n\n## Introduction\n\nThis PostHTML plugin can prepend a string to various HTML attribute values and CSS property values.\n\nInput:\n\n```html\n\u003cimg src=\"test.jpg\"\u003e\n```\n\nOutput:\n\n```html\n\u003cimg src=\"https://example.com/test.jpg\"\u003e\n```\n\nWorks on the following attributes:\n\n- `src=\"\"`\n- `href=\"\"`\n- `srcset=\"\"`\n- `poster=\"\"`\n- `background=\"\"`\n\n... and the following CSS properties:\n\n- `background: url()`\n- `background-image: url()`\n- `@font-face { src: url() }`\n\nBoth `\u003cstyle\u003e` tags and `style=\"\"` attributes are supported.\n\nCSS property values with multiple `url()` sources are supported as well.\n\n## Install\n\n```\nnpm i posthtml posthtml-base-url\n```\n\n## Usage\n\n```js\nimport posthtml from 'posthtml'\nimport baseUrl from 'posthtml-base-url'\n\nposthtml([\n  baseUrl({\n    url: 'https://example.com', \n    tags: ['img']\n  })\n])\n  .process('\u003cimg src=\"test.jpg\"\u003e')\n  .then(result =\u003e console.log(result.html))\n```\n\nResult:\n\n```html\n\u003cimg src=\"https://example.com/test.jpg\"\u003e\n```\n\n## Absolute URLs\n\nIf the target attribute value is an URL, the plugin will not modify it.\n\nIf the prefix string to prepend to the target attribute value is an URL, the two strings will be concatenated.\n\n## Relative paths\n\nIf both the prefix and the attribute value are relative paths, the plugin will intelligently join the paths instead of simply concatenating them.\n\n## Options\n\nYou can configure what to prepend to which attribute values.\n\n### `url`\n\nType: `string`\\\nDefault: `''`\n\nThe string to prepend to the attribute value.\n\n### `allTags`\n\nType: `boolean`\\\nDefault: `false`\n\nThe plugin is opt-in, meaning that by default it doesn't affect any tag.\n\nWhen you set `allTags` to `true`, the plugin will prepend your `url` to all attribute values in all the tags that it supports.\n\n### `styleTag`\n\nType: `boolean`\\\nDefault: `false`\n\nWhen set to `true`, the plugin will prepend your `url` to all `url()` sources in `\u003cstyle\u003e` tags.\n\n### `inlineCss`\n\nType: `boolean`\\\nDefault: `false`\n\nWhen set to `true`, the plugin will prepend your `url` to all `url()` sources in `style=\"\"` attributes.\n\n### `tags`\n\nType: `array|object`\\\nDefault: [defaultTags](./lib/index.js) (object)\n\nDefine a list of tags and their attributes to handle.\n\nWhen using the `tags` option, the plugin will _only handle those tags_.\n\n#### Array `tags`\n\nTo replace all known attributes for a list of tags, use the array format:\n\n```js\nposthtml([\n  baseUrl({\n    url: 'https://example.com',\n    tags: ['img', 'script'],\n  })\n])\n  .process(\n    `\u003ca href=\"foo/bar.html\"\u003e\n      \u003cimg src=\"img.jpg\" srcset=\"img-HD.jpg 2x,img-xs.jpg 100w\"\u003e\n    \u003c/a\u003e\n    \n    \u003cscript src=\"javascript.js\"\u003e\u003c/script\u003e`\n  )\n  .then(result =\u003e console.log(result.html))\n```\n\nResult:\n\n```html\n\u003ca href=\"foo/bar.html\"\u003e\n  \u003cimg src=\"https://example.com/img.jpg\" srcset=\"https://example.com/img-HD.jpg 2x, https://example.com/img-xs.jpg 100w\"\u003e\n\u003c/a\u003e\n\n\u003cscript src=\"https://example.com/javascript.js\"\u003e\u003c/script\u003e\n```\n\n#### Object `tags`\n\nYou may use an object for granular control over how specific attributes should be handled:\n\n```js\nposthtml([\n  baseUrl({\n    url: 'https://foo.com/',\n    tags: {\n      img: {\n        src: true,\n        srcset: 'https://bar.com/',\n      },\n    },\n  })\n])\n  .process(\n    `\u003ca href=\"foo/bar.html\"\u003e\n      \u003cimg src=\"img.jpg\" srcset=\"img-HD.jpg 2x, img-xs.jpg 100w\"\u003e\n    \u003c/a\u003e`\n  )\n  .then(result =\u003e console.log(result.html))\n```\n\nResult:\n\n```html\n\u003ca href=\"foo/bar.html\"\u003e\n  \u003cimg src=\"https://foo.com/img.jpg\" srcset=\"https://bar.com/img-HD.jpg 2x, https://bar.com/img-xs.jpg 100w\"\u003e\n\u003c/a\u003e\n```\n\nYou may set the value of an attribute to `true` and the plugin will use the `url` option value - we did that above for the `src` attribute.\n\n### `attributes`\n\nType: `object`\\\nDefault: `{}`\n\nKey-value pairs of attributes and what to prepend to them.\n\nExample:\n\n```js\nposthtml([\n  baseUrl({\n    attributes: {\n      'data-url': 'https://example.com/',\n    }\n  })\n])\n  .process('\u003cdiv data-url=\"foo/bar.html\"\u003e\u003c/div\u003e')\n  .then(result =\u003e console.log(result.html))\n```\n\nResult:\n\n```html\n\u003cdiv data-url=\"https://example.com/foo/bar.html\"\u003e\u003c/div\u003e\n```\n\n[npm]: https://www.npmjs.com/package/posthtml-base-url\n[npm-version-shield]: https://img.shields.io/npm/v/posthtml-base-url.svg\n[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-base-url\n[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-base-url.svg\n[github-ci]: https://github.com/posthtml/posthtml-base-url/actions/workflows/nodejs.yml\n[github-ci-shield]: https://github.com/posthtml/posthtml-base-url/actions/workflows/nodejs.yml/badge.svg\n[license]: ./LICENSE\n[license-shield]: https://img.shields.io/npm/l/posthtml-base-url.svg\n","funding_links":["https://github.com/sponsors/maizzle","https://patreon.com/posthtml","https://opencollective.com/posthtml","https://mailviews.com"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-base-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-base-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-base-url/lists"}