Skip to content

Instantly share code, notes, and snippets.

@Snapstromegon
Last active December 30, 2023 13:23
Show Gist options
  • Save Snapstromegon/1f643930a37d0383f414eb2bfc8492dc to your computer and use it in GitHub Desktop.
Save Snapstromegon/1f643930a37d0383f414eb2bfc8492dc to your computer and use it in GitHub Desktop.
11ty Issue 3133
const pluginWebc = require("@11ty/eleventy-plugin-webc");
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(pluginWebc);
eleventyConfig.addJavaScriptFunction("sRef", async () => {
try {
const response = await fetch(`https://swapi.dev/api/people/1`);
if (!response.ok) {
throw new Error(`Error fetching data: ${response.statusText}`);
}
const data = await response.json();
return data.name;
} catch (error) {
console.error(`Error fetching data from Sanity: ${error.message}`);
return null;
}
});
};
<code @text="sRef()"></code>
{
"name": "issue-3133",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@11ty/eleventy": "^2.0.1",
"@11ty/eleventy-plugin-webc": "^0.11.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment