Add BBCode support

main
Astoria 1 year ago
parent cb7c531373
commit cef3ca2892

@ -2,6 +2,7 @@
require 'sinatra'
require 'erb'
require 'date'
require 'ruby-bbcode'
class Page
@path

@ -14,6 +14,7 @@
<%= erb :asidemenu %>
<div class="content">
<%= erb :blogbar, locals: {title: title} %>
<% addtags = { :rbe => { html_open: "\<%=", html_close: "%\>" }, :rb => { html_open: "\<%", html_close: "%\>" } } %>
<div class="article">
<% if File.exist?("." + request.path_info) && request.path_info.end_with?(".erb") %>
<%= ERB.new(File.read("." + request.path_info)).result(binding) %>
@ -23,6 +24,10 @@
<%= markdown(File.read("." + request.path_info)) %>
<% elsif File.exist?("." + request.path_info + ".md") %>
<%= markdown(File.read("." + request.path_info + ".md")) %>
<% elsif File.exist?("." + request.path_info) && request.path_info.end_with?(".bb") %>
<%= ERB.new(File.read("." + request.path_info).gsub("\n[rb]", '[rb]').bbcode_to_html(false, addtags) + "<br>").result(binding) %>
<% elsif File.exist?("." + request.path_info + ".bb") %>
<%= ERB.new(File.read("." + request.path_info + ".bb").gsub("\n[rb]", '[rb]').bbcode_to_html(false, addtags)+ "<br>").result(binding) %>
<% end %>
<% if File.exist?("." + request.path_info + ".meta") %>
<div class="articledate">
@ -36,6 +41,14 @@
<div class="articledate">
<%= File.read("." + request.path_info + ".md.meta") %>
</div>
<% elsif File.exist?("." + request.path_info + ".bb.meta") %>
<div class="articledate">
<%= File.read("." + request.path_info + ".bb.meta") %>
</div>
<% else %>
<div class="articledate">
1970.01.01
</div>
<% end %>
</div>
</div>

@ -3,8 +3,10 @@
<%= markdown(File.read(file)) %>
<% elsif file.end_with?(".erb") %>
<%= ERB.new(File.read(file)).result(binding) %>
<% elsif file.end_with?(".bb") %>
<% addtags = { :rbe => { html_open: "\<%=", html_close: "%\>" }, :rb => { html_open: "\<%", html_close: "%\>" } } %>
<%= ERB.new(File.read(file).gsub("\n[rb]", '[rb]').bbcode_to_html(false, addtags) + "<br>").result(binding) %>
<% end %>
<span class="seemore">
<span class="seemore">
<b>
<span class="seedate"><%= date %></span>

@ -4,7 +4,7 @@
<% contents = Dir.children("./" + folder).grep(/#{searchquery}/) %>
<% if !contents.empty? %>
<% contents.each do |content| %>
<% if content.end_with?(".erb") || content.end_with?(".md") %>
<% if content.end_with?(".erb") || content.end_with?(".md") || content.end_with?(".bb") %>
<% if File.exists?("./" + folder + "/" + content + ".meta") %>
<% newPage = Page.new(folder + "/" + content, DateTime.parse(File.read("./" + folder + "/" + content + ".meta"), "%Y.%m.%d")) %>
<% else %>
@ -24,9 +24,7 @@
<% contentsArray.sort_by! { |page| page.getdate } %>
<% contentsArray.reverse.each do |content| %>
<% if content.getpath.end_with?(".erb") %>
<% if content.getpath.end_with?(".erb") || content.getpath.end_with?(".md") || content.getpath.end_with?(".bb") %>
<%= erb :blogwindow, locals: {file: "./" + content.getpath, date: content.getdate.strftime("%Y.%m.%d")} %>
<% elsif content.getpath.end_with?(".md") %>
<%= erb :blogwindow, locals: {file: "./" + content.getpath, date: content.getdate.strftime("%Y.%m.%d")} %>
<% end %>
<% end %>
Loading…
Cancel
Save