Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 committed Dec 31, 2023
1 parent 0d4b535 commit a9a7a9f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions document-generator/generator.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class DocumentGenerator
alias Docs = Hash(String, Hash(String, Hash(String, String) | String))
@documents : Docs
alias Docs = Hash(String, Hash(String, Hash(String, String)))
getter documents : Docs
def initialize
@documents = Docs.new
end
Expand All @@ -9,22 +9,27 @@ class DocumentGenerator
Dir.new(path).each_child do |folder|
Dir.new(Path.new(path, folder)).each_child do |file|
if file == "about.md"
p read_markdown(File.read(Path.new(path, folder, file)))
@documents[folder] = read_markdown(File.read(Path.new(path, folder, file)))
end
end
end
end

private def read_markdown(content : String)
data = Hash(String, Hash(String, String)).new
#data["content"] = content
data["chapter"] = {} of String => String
name = ""

content.split("\n").each do |line|
if line.starts_with?("#")
name = line.lstrip("# ")
data["chapter"][name] = line + "\n"
elsif line =~ /^\s*\[[^\]]+\]\s*:\s*https?:\/\/[^\s]+\s*$/
if data["chapter"].has_key?("links")
data["chapter"]["links"] += line + "\n"
else
data["chapter"]["links"] = line + "\n"
end
else
data["chapter"][name] += line + "\n"
end
Expand All @@ -34,9 +39,20 @@ class DocumentGenerator

def load_template(path : String)
content = File.read(path)
content.each_line do |line|
match = line.match(/{%\s*([^%\s]+)\s*%}/)
p match
if match
p match[1]
end
end

end
end

document = DocumentGenerator.new
document.read_documents("./concepts")

#p document.documents

document.load_template("./template.md")

0 comments on commit a9a7a9f

Please sign in to comment.