@@ -6,27 +6,38 @@ namespace MarkdownUtil.Service.Visitors;
66
77public class MarkdigVisitor : BaseVisitor
88{
9- public MarkdigVisitor ( string rootPath , string outPath , HtmlRenderer htmlFoundation ) : base ( rootPath , outPath , ".html" )
9+ public MarkdigVisitor (
10+ string rootPath ,
11+ string outPath ,
12+ HtmlRenderer htmlFoundation ,
13+ string editPageRoot ) : base ( rootPath , outPath , ".html" )
1014 {
1115 _htmlFoundation = htmlFoundation ;
16+ _editPageRoot = editPageRoot ;
1217 }
1318
1419 private readonly HtmlRenderer _htmlFoundation ;
20+ private readonly string _editPageRoot ;
1521
1622 protected override bool ProcessFile ( MarkdownFile entity , int graphDepth , FilePathInfo io )
1723 {
1824 AnsiConsole . WriteLine ( $ "{ io . InputRelativeFilePathToRootDirectory } => { io . OutputRelativeFilePathToRootDirectory } ") ;
1925
2026 var markdown = io . ReadAllText ( ) ;
21- io . CreateOutputDirectory ( ) ;
22- io . DeleteOutputFileIfExists ( ) ;
27+ io . CreateOutputDirectory ( ) ; // ensures that the output directory exits
28+ io . DeleteOutputFileIfExists ( ) ; // deletes old output file if it exits
2329
30+ var editPageLink = string . IsNullOrEmpty ( _editPageRoot ) ? string . Empty : Path . Combine ( _editPageRoot , io . InputRelativeFilePathToRootDirectory ) ;
31+
2432 var outputFileName = io . OutputFullFilePath ;
33+
2534 if ( outputFileName . EndsWith ( "readme.html" , StringComparison . InvariantCultureIgnoreCase ) )
2635 outputFileName = outputFileName . Substring ( 0 , outputFileName . Length - 11 ) + "index.html" ;
36+ // Delete the Output file if it already exits
37+ if ( File . Exists ( outputFileName ) ) File . Delete ( outputFileName ) ;
2738 using var fs = new FileStream ( outputFileName , FileMode . CreateNew , FileAccess . Write ) ;
2839 using var sw = new StreamWriter ( fs ) ;
29- _htmlFoundation . WriteHtml ( sw , entity . Title , "" , graphDepth , markdown ) . Wait ( ) ;
40+ _htmlFoundation . WriteHtml ( sw , entity . Title , "" , graphDepth , markdown , editPageLink ) . Wait ( ) ;
3041 return true ;
3142 }
3243}
0 commit comments