mirror of
https://github.com/iptv-org/iptv
synced 2025-12-17 10:57:18 -05:00
Update scripts
This commit is contained in:
@@ -1,33 +1,37 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
export class Markdown {
|
||||
filepath: string
|
||||
type MarkdownConfig = {
|
||||
build: string
|
||||
template: string
|
||||
}
|
||||
|
||||
constructor(filepath: string) {
|
||||
this.filepath = filepath
|
||||
export class Markdown {
|
||||
build: string
|
||||
template: string
|
||||
|
||||
constructor(config: MarkdownConfig) {
|
||||
this.build = config.build
|
||||
this.template = config.template
|
||||
}
|
||||
|
||||
compile() {
|
||||
const config = JSON.parse(fs.readFileSync(this.filepath, 'utf8'))
|
||||
const workingDir = process.cwd()
|
||||
|
||||
config.files.forEach((templateFile: string) => {
|
||||
const templatePath = path.resolve(workingDir, templateFile)
|
||||
const content = fs.readFileSync(templatePath, 'utf8')
|
||||
const processedContent = this.processIncludes(content, workingDir)
|
||||
|
||||
if (config.build) {
|
||||
const outputPath = path.resolve(workingDir, config.build)
|
||||
fs.writeFileSync(outputPath, processedContent, 'utf8')
|
||||
}
|
||||
})
|
||||
const workingDir = process.cwd()
|
||||
|
||||
const templatePath = path.resolve(workingDir, this.template)
|
||||
const template = fs.readFileSync(templatePath, 'utf8')
|
||||
const processedContent = this.processIncludes(template, workingDir)
|
||||
|
||||
if (this.build) {
|
||||
const outputPath = path.resolve(workingDir, this.build)
|
||||
fs.writeFileSync(outputPath, processedContent, 'utf8')
|
||||
}
|
||||
}
|
||||
|
||||
private processIncludes(content: string, baseDir: string): string {
|
||||
private processIncludes(template: string, baseDir: string): string {
|
||||
const includeRegex = /#include\s+"([^"]+)"/g
|
||||
|
||||
return content.replace(includeRegex, (match, includePath) => {
|
||||
|
||||
return template.replace(includeRegex, (match, includePath) => {
|
||||
try {
|
||||
const fullPath = path.resolve(baseDir, includePath)
|
||||
const includeContent = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
Reference in New Issue
Block a user