You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.7 KiB
Ruby
85 lines
1.7 KiB
Ruby
class Page
|
|
@file
|
|
@path
|
|
@link
|
|
@metadata
|
|
@@ADDTAGS = { :rbe => { html_open: "\<%=", html_close: "%\>" }, :rb => { html_open: "\<%", html_close: "%\>" } }
|
|
def initialize(path)
|
|
@path = path
|
|
@link = "https://broken-moon.net/" + path
|
|
begin
|
|
@file = File.readlines(path)
|
|
rescue
|
|
raise "Invalid page at " + path
|
|
end
|
|
if @file[0] == "+++\n"
|
|
@metadata = get_toml_meta
|
|
else
|
|
raise "No Metadata"
|
|
end
|
|
end
|
|
|
|
def get_date
|
|
if @metadata.has_key?("date")
|
|
return @metadata["date"]
|
|
else
|
|
return "1970.1.1"
|
|
end
|
|
end
|
|
|
|
def get_title
|
|
if @metadata.has_key?("title")
|
|
return @metadata["title"]
|
|
else
|
|
return "No title"
|
|
end
|
|
end
|
|
|
|
def get_description
|
|
if @metadata.has_key?("description")
|
|
return @metadata["description"]
|
|
else
|
|
return "No description"
|
|
end
|
|
end
|
|
|
|
def get_link
|
|
if @metadata.has_key?("link")
|
|
return @metadata["link"]
|
|
else
|
|
return @link
|
|
end
|
|
end
|
|
|
|
def get_path
|
|
return @path
|
|
end
|
|
|
|
def get_toml_meta
|
|
startIndex = @file.find_index("+++\n")
|
|
@file[startIndex] = ""
|
|
endIndex = @file.find_index("+++\n")
|
|
tomlString = @file[startIndex+1..endIndex-1].join
|
|
@file.slice!(startIndex, endIndex + 1)
|
|
# JANK AS SHIT, WILL HURT ME
|
|
return TOML.load(tomlString)
|
|
end
|
|
|
|
def render
|
|
case @metadata["format"]
|
|
when "markdown"
|
|
return Kramdown::Document.new(@file.join).to_html
|
|
when "erb"
|
|
return ERB.new(@file.join).result(binding)
|
|
when "bbcode"
|
|
return ERB.new(@file.join.concat("\n").gsub("\n[rb]", '[rb]').bbcode_to_html(false, @@ADDTAGS)).result(binding)
|
|
else
|
|
return @file
|
|
end
|
|
end
|
|
|
|
|
|
def get_feed_entry
|
|
return " <item>\n <title>" + get_title + "</title>\n <link>" + get_link + "</link>\n <description>" + get_description + "</description>\n </item>"
|
|
end
|
|
end |