{"id":15016453,"url":"https://github.com/ashur/eleventy-plugin-add-remote-data","last_synced_at":"2025-04-12T09:32:52.212Z","repository":{"id":214697864,"uuid":"737141756","full_name":"ashur/eleventy-plugin-add-remote-data","owner":"ashur","description":"Fetch remote data from one or more URLs and expose each response as an Eleventy global data variable","archived":false,"fork":false,"pushed_at":"2024-01-03T16:56:19.000Z","size":62,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T07:05:36.718Z","etag":null,"topics":["11ty","eleventy","eleventy-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashur.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2023-12-30T00:31:20.000Z","updated_at":"2024-12-24T00:17:11.000Z","dependencies_parsed_at":"2024-09-20T13:02:13.191Z","dependency_job_id":null,"html_url":"https://github.com/ashur/eleventy-plugin-add-remote-data","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"3a9a21bbc5a3833f38afc27b843c8ba03058ea4a"},"previous_names":["ashur/eleventy-plugin-add-remote-data"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashur%2Feleventy-plugin-add-remote-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashur%2Feleventy-plugin-add-remote-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashur%2Feleventy-plugin-add-remote-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashur%2Feleventy-plugin-add-remote-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashur","download_url":"https://codeload.github.com/ashur/eleventy-plugin-add-remote-data/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248546313,"owners_count":21122290,"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":["11ty","eleventy","eleventy-plugin"],"created_at":"2024-09-24T19:48:53.849Z","updated_at":"2025-04-12T09:32:51.934Z","avatar_url":"https://github.com/ashur.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eleventy-plugin-add-remote-data\n\nAn [Eleventy](https://11ty.dev/) plugin for fetching remote JSON data from one or more endpoints and\nexposing each response as a [global data](https://www.11ty.dev/docs/data-global-custom/) variable.\n\n## Setup\n\nRun the following command at the root of your Eleventy project:\n\n```shell\nnpm install @aaashur/eleventy-plugin-add-remote-data\n```\n\nNext, include the plugin in your [Eleventy config file](https://www.11ty.dev/docs/config/#default-filenames):\n\n```javascript\nconst addRemoteData = require(\"@aaashur/eleventy-plugin-add-remote-data\");\n\nmodule.exports = (eleventyConfig) =\u003e {\n    eleventyConfig.addPlugin(addRemoteData, {\n        data: {\n            // See \"Usage\" below\n        },\n    });\n};\n```\n\n## Usage\n\nUse the `data` property of the plugin options object to define the name of one or more global data variables and the remote URL of its source data.\n\nFor example, the following configuration:\n\n```javascript\neleventyConfig.addPlugin(addRemoteData, {\n    data: {\n        robots: \"https://api.ashur.cab/robots/v2.json\"\n    },\n});\n```\n\nwould create a global data variable named `robots` that you might use in a template like this:\n\n```njk\n---\npermalink: /robots.txt\n---\n{%- for robot in robots.disallow -%}\nUser-agent: {{ robot }}\nDisallow: /\n\n{% endfor -%}\n```\n\nAdding a second data property `coinToss` would create a global data variable named `coinToss`:\n\n```javascript\n    data: {\n        coinToss: \"https://coin-toss.netlify.app/api/v1.json\",\n        robots: \"https://api.ashur.cab/robots/v2.json\"\n    },\n```\n\netc.\n\n## Configuration\n\nThis plugin uses [`@11ty/eleventy-fetch`](https://www.npmjs.com/package/@11ty/eleventy-fetch) under the hood, and accepts all the same [options](https://www.11ty.dev/docs/plugins/fetch/#options).\n\nIn addition to the top-level `data` property, you can set an `options` property to adjust default behaviors.\n\n```javascript\neleventyConfig.addPlugin(addRemoteData, {\n    data: {\n        // ...\n    },\n    options: {\n        // ...\n    },\n});\n```\n\n### Cache\n\nBy default, `eleventy-fetch` caches results for 1 day and stores them in a directory called `.cache`.\n\nTo use a different directory or duration, use the `options` object to set one or both for all endpoints:\n\n```javascript\neleventyConfig.addPlugin(addRemoteData, {\n    data: {\n        // ...\n    },\n    options: {\n        directory: \"different-cache-directory\",\n        duration: \"30d\",\n    },\n});\n```\n\nIf you're working with global data variables that have different requirements, you can define `options` on an individual basis:\n\n```javascript\neleventyConfig.addPlugin(addRemoteData, {\n    data: {\n        coinToss: {\n            options: {\n                duration: \"0d\",\n\n                // Because we haven't defined `directory`, this endpoint will\n                // inherit the \"different-cache-directory\" value from default\n                // options defined below\n            },\n\n            url: \"https://coin-toss.netlify.app/api/v1.json\",\n        },\n\n        robots: \"https://api.ashur.cab/robots/v2.json\",\n    },\n\n    options: {\n    \t// Default options\n        directory: \"different-cache-directory\",\n        duration: \"30d\",\n    },\n});\n```\n\nOptions for individual endpoints will be merged with default options, allowing you to fine-tune just the properties you need.\n\n### Type\n\nFor convenience, this plugin assumes a valid JSON response by default — if it encounters an invalid payload, an exception will be thrown.\n\nTo switch to [another type supported by `eleventy-fetch`](https://www.11ty.dev/docs/plugins/fetch/#type), you can set `type` on both the top-level `options` object:\n\n```javascript\neleventyConfig.addPlugin(addRemoteData, {\n    data: {\n        // ...\n    },\n    options: {\n        type: \"text\",\n    },\n}\n```\n\nand on a per-endpoint basis:\n\n```javascript\neleventyConfig.addPlugin(addRemoteData, {\n    data: {\n        coinToss: {\n            type: \"json\",\n            url: \"https://coin-toss.netlify.app/api/v1.json\",\n        },\n    },\n    options: {\n        type: \"text\",\n    },\n}\n```\n\n### Security \u0026 Privacy\n\nIf you haven't worked with `eleventy-fetch` before, please be sure to read (and heed) [this warning](https://www.11ty.dev/docs/plugins/fetch/#installation):\n\n\u003e **Important Security and Privacy Notice**\n\u003e\n\u003e This plugin caches complete network responses. Unless you’re willing to perform a full review of everything this plugin caches to disk for privacy and security exposure, it is strongly recommended that you add the .cache folder to your .gitignore file so that network responses aren’t checked in to your git repository.\n\n## FAQ\n\n### Why choose this over using `eleventy-fetch` directly?\n\nIf you find yourself writing global data files that are largely identical, fetching remote JSON data and exporting the results directly, this plugin can help eliminate a lot of the friction in getting set up.\n\nIf, however, your needs are more complex — ex., the remote data must be processed or sanitized, or you’re fetching raw image data that needs to be optimized — using `eleventy-fetch` directly is definitely the right choice!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashur%2Feleventy-plugin-add-remote-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashur%2Feleventy-plugin-add-remote-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashur%2Feleventy-plugin-add-remote-data/lists"}