File tree Expand file tree Collapse file tree 5 files changed +33
-7
lines changed Expand file tree Collapse file tree 5 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,10 @@ async function seed() {
4343 updatedAt : new Date ( '01/01/2020' ) ,
4444 title : 'Changelog 3' ,
4545 slug : 'changelog-3' ,
46- content : 'Changelog 3 content with [markdown content](https://de.wikipedia.org/wiki/Markdown)' ,
47- summary : 'Changelog 3 summary with [markdown content](https://de.wikipedia.org/wiki/Markdown)' ,
46+ content :
47+ 'Changelog 3 content with [markdown content](https://de.wikipedia.org/wiki/Markdown)' ,
48+ summary :
49+ 'Changelog 3 summary with [markdown content](https://de.wikipedia.org/wiki/Markdown)' ,
4850 published : true ,
4951 deleted : false ,
5052 } ,
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export async function GET() {
1414 ttl : 60 ,
1515 } ) ;
1616
17- const allChangelogs = await getChangelogs ( ) ;
17+ const { changelogs : allChangelogs } = await getChangelogs ( ) ;
1818
1919 if ( allChangelogs ) {
2020 allChangelogs
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {Element} from 'hast';
1313export const dynamic = 'force-dynamic' ;
1414
1515export default async function Page ( ) {
16- const changelogs = await getChangelogs ( ) ;
16+ const { changelogs} = await getChangelogs ( ) ;
1717
1818 const changelogsWithPublishedAt = changelogs . filter ( changelog => {
1919 return changelog . publishedAt !== null ;
Original file line number Diff line number Diff line change 1+ import { getChangelogs } from '@/server/utils' ;
12import './globals.css' ;
23
34import { Theme } from '@radix-ui/themes' ;
@@ -30,10 +31,11 @@ export const metadata: Metadata = {
3031 } ,
3132} ;
3233
33- export default function RootLayout ( { children} : { children : React . ReactNode } ) {
34+ export default async function RootLayout ( { children} : { children : React . ReactNode } ) {
35+ const { hash : chngelogsHash } = await getChangelogs ( ) ;
3436 return (
3537 < html lang = "en" >
36- < body className = { `${ rubik . variable } ` } >
38+ < body className = { `${ rubik . variable } ` } data-content-hash = { chngelogsHash } >
3739 < Theme accentColor = "iris" grayColor = "sand" radius = "large" scaling = "95%" >
3840 { children }
3941 </ Theme >
Original file line number Diff line number Diff line change 11import { prismaClient } from '@/server/prisma-client' ;
2+ import { Changelog } from '@prisma/client' ;
23import { unstable_cache } from 'next/cache' ;
34
45export const getChangelogs = unstable_cache (
56 async ( ) => {
6- return await prismaClient . changelog . findMany ( {
7+ const changelogs = await prismaClient . changelog . findMany ( {
78 include : {
89 categories : true ,
910 } ,
@@ -14,6 +15,27 @@ export const getChangelogs = unstable_cache(
1415 publishedAt : 'desc' ,
1516 } ,
1617 } ) ;
18+ const hashHex = ( buffer : ArrayBuffer ) => {
19+ const hexCodes = Array . from ( new Uint8Array ( buffer ) ) . map ( value =>
20+ value . toString ( 16 ) . padStart ( 2 , '0' )
21+ ) ;
22+ return hexCodes . join ( '' ) ;
23+ } ;
24+ const hashChangelogs = ( changelogs : Changelog [ ] ) =>
25+ crypto . subtle
26+ . digest (
27+ 'SHA-256' ,
28+ new TextEncoder ( ) . encode (
29+ changelogs
30+ . map ( changelogs => changelogs . id + ':' + changelogs . updatedAt )
31+ . join ( ',' )
32+ )
33+ )
34+ . then ( hashHex ) ;
35+ return {
36+ changelogs,
37+ hash : await hashChangelogs ( changelogs ) ,
38+ } ;
1739 } ,
1840 [ 'changelogs' ] ,
1941 { tags : [ 'changelogs' ] }
You can’t perform that action at this time.
0 commit comments