diff --git a/pages/blog/[blog].js b/pages/blog/[blog].js index 1b1e85e..dc7fb63 100644 --- a/pages/blog/[blog].js +++ b/pages/blog/[blog].js @@ -12,6 +12,8 @@ import styles from "../../style/bloga.module.css" import { ANDROID_URL, IOS_URL } from "../../constants" import appStorePic from "../../public/images/other/app-store-fr.png" import googlePlayPic from "../../public/images/other/google-play-fr.png" +import { parse } from "date-fns" +import { fr } from "date-fns/locale" const Blog = ({ mdxSource, data }) => { const [showPopup, setShowPopup] = useState(false) @@ -89,6 +91,18 @@ export async function getStaticProps({ params }) { const fileContents = fs.readFileSync(filePath, "utf-8") const { content, data } = matter(fileContents) const mdxSource = await serialize(content) + + const articleDate = parse(data.date, "MMMM d, yyyy", new Date(), { + locale: fr, + }) + + const currentDate = new Date() + + if (articleDate >= currentDate) { + return { + notFound: true, + } + } return { props: { mdxSource, diff --git a/pages/blog/index.js b/pages/blog/index.js index 21fff7e..07933c8 100644 --- a/pages/blog/index.js +++ b/pages/blog/index.js @@ -7,6 +7,8 @@ import Head from "next/head" import Navigation, { DownloadPopup } from "../../components/Navigation" import Footer from "../../components/Footer" import BlogCard from "../../components/BlogCard" +import { parse } from "date-fns" +import { fr } from "date-fns/locale" const Index = ({ posts }) => { const [showPopup, setShowPopup] = useState(false) @@ -27,6 +29,7 @@ const Index = ({ posts }) => {
{posts + .filter((post) => !post.notFound) .sort((a, b) => a.order - b.order) .map((post) => ( = currentDate) { + return { + notFound: true, + } + } return { ...data, diff --git a/pages/site-map.xml.js b/pages/site-map.xml.js index 7a3cceb..9e50830 100644 --- a/pages/site-map.xml.js +++ b/pages/site-map.xml.js @@ -88,6 +88,11 @@ export async function getStaticProps() { const parsedDate = data.date ? parse(data.date, "MMMM d, yyyy", new Date(), { locale: fr }) : null + const currentDate = new Date() + + if (parsedDate >= currentDate) { + return null + } return { ...data, mdxSource, @@ -99,7 +104,7 @@ export async function getStaticProps() { }) ) - const sitemap = generateSiteMap(posts) + const sitemap = generateSiteMap(posts.filter((post) => post !== null)) fs.writeFileSync(path.join(process.cwd(), "public", "sitemap.xml"), sitemap)