Skip to content

Commit

Permalink
feat: add date
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanRos committed Dec 28, 2023
1 parent 4979053 commit bdf2826
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion content/reussir-son-dry-january-avec-oz-ensemble.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: "reussir-son-dry-january-avec-oz-ensemble"
order: 1
category: "Santé et bien-être"
image: ../images/articles/dry-january-wiki.png
date: Decembre 13, 2023
date: Décembre 23, 2024
description: "Le Dry January est une campagne de santé publique qui consiste à s'abstenir de boire de l'alcool pendant tout le mois de janvier. Pour réussir ce défi personnel, il est important de comprendre ses motivations. Il est aussi utile d'identifier les déclencheurs de sa consommation et de trouver des alternatives saines. Planifier des activités sans alcool et obtenir le soutien social de ses proches peuvent aider. L'application Oz Ensemble est un outil précieux pour gérer sa consommation, fixer des objectifs réalistes, recevoir des récompenses, trouver du soutien dans une communauté et accéder à des ressources informatives. Le Dry January est une occasion de repenser sa relation avec l'alcool, d'améliorer sa santé et de découvrir de nouvelles activités enrichissantes."
---

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"@next/font": "13.1.6",
"@socialgouv/matomo-next": "^1.2.2",
"@types/mdx": "^2.0.10",
"date-fns": "^3.0.6",
"fs": "^0.0.1-security",
"fs-extra": "^11.2.0",
"gray-matter": "^4.0.3",
"next": "13.1.6",
"next-compose-plugins": "^2.2.1",
Expand Down
18 changes: 16 additions & 2 deletions pages/site-map.xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import fs from "fs"
import matter from "gray-matter"
import path from "path"
import { serialize } from "next-mdx-remote/serialize"
import { stats } from "fs-extra"
import { format, parse } from "date-fns"
import { fr } from "date-fns/locale"

const URL = "https://ozensemble.fabrique.social.gouv.fr"

Expand Down Expand Up @@ -54,10 +57,11 @@ function generateSiteMap(posts) {
<priority>0.80</priority>
</url>
${posts
.map(({ slug }) => {
.map(({ slug, lastmod }) => {
return `
<url>
<loc>${`${URL}/blog/${slug}`}</loc>
<lastmod>${lastmod}</lastmod>
</url>
`
})
Expand All @@ -66,6 +70,10 @@ function generateSiteMap(posts) {
`
}

export default function SiteMap() {
return <div>{/* Render your sitemap content here */}</div>
}

export async function getStaticProps() {
const files = fs.readdirSync(path.join(process.cwd(), "content"))

Expand All @@ -77,16 +85,22 @@ export async function getStaticProps() {
const rawContent = fs.readFileSync(filePath, "utf8")
const { content, data } = matter(rawContent)
const mdxSource = await serialize(content)

const parsedDate = data.date
? parse(data.date, "MMMM d, yyyy", new Date(), { locale: fr })
: null
return {
...data,
mdxSource,
slug: filename.replace(".mdx", ""),
lastmod: parsedDate
? format(parsedDate, "yyyy-MM-dd")
: stats.mtime.toISOString(),
}
})
)

const sitemap = generateSiteMap(posts)

fs.writeFileSync(path.join(process.cwd(), "public", "sitemap.xml"), sitemap)

return {
Expand Down
1 change: 1 addition & 0 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<url>
<loc>https://ozensemble.fabrique.social.gouv.fr/blog/reussir-son-dry-january-avec-oz-ensemble</loc>
<lastmod>2024-12-23</lastmod>
</url>

</urlset>
Expand Down
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,11 @@ data-urls@^2.0.0:
whatwg-mimetype "^2.3.0"
whatwg-url "^8.0.0"

date-fns@^3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.0.6.tgz#fe3aeb7592d359f075ffc41cb16139828810ca83"
integrity sha512-W+G99rycpKMMF2/YD064b2lE7jJGUe+EjOES7Q8BIGY8sbNdbgcs9XFTZwvzc9Jx1f3k7LB7gZaZa7f8Agzljg==

debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
Expand Down Expand Up @@ -2914,6 +2919,15 @@ fragment-cache@^0.2.1:
dependencies:
map-cache "^0.2.2"

fs-extra@^11.2.0:
version "11.2.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b"
integrity sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -3074,6 +3088,11 @@ gopd@^1.0.1:
dependencies:
get-intrinsic "^1.1.3"

graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==

graceful-fs@^4.2.4:
version "4.2.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
Expand Down Expand Up @@ -4273,6 +4292,15 @@ json5@^2.2.2:
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

"jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.3.2:
version "3.3.3"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.3.3.tgz#76b3e6e6cece5c69d49a5792c3d01bd1a0cdc7ea"
Expand Down Expand Up @@ -6926,6 +6954,11 @@ universalify@^0.2.0:
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==

universalify@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.1.tgz#168efc2180964e6386d061e094df61afe239b18d"
integrity sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==

unset-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
Expand Down

0 comments on commit bdf2826

Please sign in to comment.