Alex Riviere
Developer Experience Engineer @ MURAL
Find me online: @fimion
Blog: https://alex.party
With many thanks, and apologies to Chris Coyier
<section id="articles"></section>
<script>
startApp(articles){
// add articles to our section#articles
}
</script>
<script src="https://css-tricks.com/{path to api for posts}/?_jsonp=startApp">
</script>
function renderArticles(articles){
const result = ""
// add all the articles we get to result
return result;
}
function createHTMLDoc(response){
const indexBody = `
<!DOCTYPE html>
<html>
<body>
<section>{{addArticles}}</section>
</body>
</html>
`;
const articles = JSON.parse(response.body);
return indexBody.replace('{{addArticles}}', renderArticles(articles));
}
// To be continued...
// ... part 2
const request = require('./httpPromise.js');
exports.handler = async function (){
const requestOpts = new URL("https://css-tricks.com/{path to api}");
try {
const cssTricksResponse = await request(requestOpts);
return {
statusCode:200,
headers:{"content-type":'text/html'},
body: createHTMLDoc(cssTricksResponse),
};
} catch(e) {
console.log(e);
return { statusCode: 500, body: JSON.stringify(e)};
}
}
* latest greatest hippest and hottest not guaranteed
const {builder} = require("@netlify/functions");
const request = require('./httpPromise.js');
exports.handler = builder(async function (){
const requestOpts = new URL("https://css-tricks.com/{path to api}");
try {
const cssTricksResponse = await request(requestOpts);
return {
statusCode:200,
headers:{"content-type":'text/html'},
body: createHTMLDoc(cssTricksResponse),
};
} catch(e) {
console.log(e);
return { statusCode: 500, body: JSON.stringify(e)};
}
});
Slides
https://slides.com/fimion/css-trickz-jamstack-conf-2021/
CSS-TRICKZ on GitHub
https://github.com/fimion/css-trickz
(I'm so sorry.)