-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For blogs with more than 512 pages, the default open file limit for most Kernels (1024) is exceeded. In this case the operating system just refuses to open any more files. Instead of using defer and wait for the files to be closed, run the (*os.File).Close function after completing working with the file instead of waiting for the function to return before closing the files. Fixes: #11 Fixes: b60fc70 ("hello world") Signed-off-by: Moritz Poldrack <[email protected]>
- Loading branch information
1 parent
a02136e
commit 3c4419f
Showing
2 changed files
with
60 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/russross/blackfriday" | ||
) | ||
|
||
// markdownToHTML converts markdown documents to HTML | ||
func markdownToHTML(inFolder, outFolder, templateFolder string) { | ||
files, _ := os.ReadDir(inFolder) | ||
|
||
for _, file := range files { | ||
// only markdown files | ||
if filepath.Ext(file.Name()) == ".md" { | ||
|
||
// open the selected markdown file | ||
markdownFile, _ := os.Open(inFolder + "/" + file.Name()) | ||
|
||
// create the html file | ||
htmlFile, _ := os.Create(outFolder + "/" + file.Name() + ".html") | ||
|
||
// read the md | ||
reader := bufio.NewReader(markdownFile) | ||
markdown, _ := io.ReadAll(reader) | ||
|
||
// send the md to blackfriday | ||
html := blackfriday.MarkdownCommon(markdown) | ||
|
||
// read in our templates | ||
header, _ := os.ReadFile(templateFolder + "/header.html") | ||
footer, _ := os.ReadFile(templateFolder + "/footer.html") | ||
|
||
// assemble in order | ||
completeHTML := string(header) + strings.TrimSpace(string(html)) + string(footer) | ||
|
||
// pass the assembled html into ScanForPluginCalls | ||
htmlAfterPlugins, htmlAfterPluginsErr := ScanForPluginCalls(completeHTML) | ||
if htmlAfterPluginsErr != nil { | ||
log.Println("error inserting plugin content: ", htmlAfterPluginsErr) | ||
log.Println("returning content without plugin...") | ||
|
||
// if there's an error, let's just take the html from before the error and use that. | ||
htmlAfterPlugins = completeHTML | ||
} | ||
|
||
// don't forget to close it when done | ||
markdownFile.Close() | ||
htmlFile.Close() | ||
|
||
fmt.Fprintln(htmlFile, htmlAfterPlugins) | ||
} | ||
} | ||
} |