This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Example 1: | |
export async function getStaticProps() { | |
const data = await axios | |
.get("https://api.priver.dev/wp-json/wp/v2/works?filter=[orderby]=date") | |
.then(d => d.data); | |
console.log(data); | |
return { props: { projects: data } }; | |
} | |
class Home extends React.Component { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import axios from "axios"; | |
const sitemapXml = data => { | |
let latestPost = 0; | |
let projectsXML = ""; | |
data.map(post => { | |
const postDate = Date.parse(post.modified); | |
if (!latestPost || postDate > latestPost) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import functions from the package | |
import { SitemapStream, streamToPromise } from "sitemap"; | |
// A custom function I use to fetch data from a backend. I will keep the import to make it more clear why "graphlqlFetch" is used in the code | |
import graphlqlFetch from "lib/apollo" | |
export default async (req, res) => { | |
// Fetch data from a source which will be used to render the sitemap. | |
const { posts } = await graphlqlFetch(` | |
query getSitemapData { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import functions from the package | |
import { SitemapStream, streamToPromise } from "sitemap"; | |
// Fetch data from a source which will be used to render the sitemap. | |
const { posts } = await graphlqlFetch(` | |
query getSitemapData { | |
projects: allWorks { | |
slug { | |
current | |
} | |
publishedAt |