1- import type { Context , Page , SecretScanningData } from '@/types'
1+ import type { Context , Page } from '@/types'
22import type { PageTransformer } from './types'
3- import fs from 'fs'
4- import yaml from 'js-yaml'
3+ import { load } from 'js-yaml'
54import path from 'path'
65import { getVersionInfo } from '@/app/lib/constants'
76import { liquid , renderContent } from '@/content-render/index'
87import { allVersions } from '@/versions/lib/all-versions'
98import { loadTemplate } from '@/article-api/lib/load-template'
9+ import { getSecretScanningData } from '@/secret-scanning/lib/get-secret-scanning-data'
1010
1111/**
1212 * Transformer for Secret Scanning pages.
@@ -35,15 +35,15 @@ export class SecretScanningTransformer implements PageTransformer {
3535 const secretScanningDir = path . join ( process . cwd ( ) , 'src/secret-scanning/data/pattern-docs' )
3636 const filepath = path . join ( secretScanningDir , versionPath , 'public-docs.yml' )
3737
38- if ( fs . existsSync ( filepath ) ) {
39- const data = yaml . load ( fs . readFileSync ( filepath , 'utf-8' ) ) as SecretScanningData [ ]
38+ try {
39+ const data = await getSecretScanningData ( filepath )
4040
4141 // Process Liquid in values
4242 for ( const entry of data ) {
4343 // Only process Liquid for the hasValidityCheck field, as in the middleware
4444 if ( typeof entry . hasValidityCheck === 'string' && entry . hasValidityCheck . includes ( '{%' ) ) {
4545 // Render Liquid and parse as YAML to get correct boolean type
46- entry . hasValidityCheck = yaml . load (
46+ entry . hasValidityCheck = load (
4747 await liquid . parseAndRender ( entry . hasValidityCheck , context ) ,
4848 ) as boolean
4949 }
@@ -54,9 +54,12 @@ export class SecretScanningTransformer implements PageTransformer {
5454 }
5555
5656 context . secretScanningData = data
57- } else {
58- // If the file does not exist, set to empty array to ensure predictable behavior
59- context . secretScanningData = [ ]
57+ } catch ( error ) {
58+ if ( ( error as NodeJS . ErrnoException ) . code === 'ENOENT' ) {
59+ context . secretScanningData = [ ]
60+ } else {
61+ throw error
62+ }
6063 }
6164 }
6265
0 commit comments