@@ -2,16 +2,21 @@ import { execFileSync } from 'node:child_process'
22import { createHash } from 'node:crypto'
33import { readFile , writeFile } from 'node:fs/promises'
44
5- export const HASH_ALGORITHM = 'shake128'
6- export const HASH_OUTPUT_BYTES = 6
75export const REVISIONS_PATH = 'www/_data/revisions.json'
86
9- export interface Revision {
10- hash : string
7+ const HASH_ALGORITHM = 'shake128'
8+ const HASH_OUTPUT_BYTES = 6
9+
10+ export interface RevisionVersion {
1111 algorithm : string
1212 outputBytes : number
1313 fields : string [ ]
1414 separator : string
15+ }
16+
17+ export interface Revision {
18+ v : number
19+ hash : string
1520 date : string
1621 commit : string
1722 message ?: string
@@ -23,7 +28,10 @@ export interface RevisionEntry {
2328 generatedTeaserHash ?: string
2429}
2530
26- export type RevisionsFile = Record < string , RevisionEntry >
31+ export interface RevisionsFile {
32+ versions : Record < string , RevisionVersion >
33+ entries : Record < string , RevisionEntry >
34+ }
2735
2836export function computeHash (
2937 title : string ,
@@ -39,10 +47,6 @@ export function computeHash(
3947 return hash . digest ( 'hex' )
4048}
4149
42- export function hashFields ( subhead : string | undefined ) : string [ ] {
43- return subhead != null ? [ 'title' , 'subhead' , 'content' ] : [ 'title' , 'content' ]
44- }
45-
4650export function computeTeaserHash ( teaser : string ) : string {
4751 const hash = createHash ( HASH_ALGORITHM , {
4852 outputLength : HASH_OUTPUT_BYTES ,
@@ -79,17 +83,21 @@ export async function loadRevisions(path: string = REVISIONS_PATH): Promise<Revi
7983 const content = await readFile ( path , 'utf-8' )
8084 return JSON . parse ( content ) as RevisionsFile
8185 } catch {
82- return { }
86+ return { versions : { } , entries : { } }
8387 }
8488}
8589
8690export async function saveRevisions (
8791 revisions : RevisionsFile ,
8892 path : string = REVISIONS_PATH
8993) : Promise < void > {
90- const sorted : RevisionsFile = { }
91- for ( const key of Object . keys ( revisions ) . sort ( ) ) {
92- sorted [ key ] = revisions [ key ]
94+ const sortedEntries : Record < string , RevisionEntry > = { }
95+ for ( const key of Object . keys ( revisions . entries ) . sort ( ) ) {
96+ sortedEntries [ key ] = revisions . entries [ key ]
97+ }
98+ const output : RevisionsFile = {
99+ versions : revisions . versions ,
100+ entries : sortedEntries ,
93101 }
94- await writeFile ( path , JSON . stringify ( sorted , null , 2 ) + '\n' )
102+ await writeFile ( path , JSON . stringify ( output , null , 2 ) + '\n' )
95103}
0 commit comments