From 418e7a38f6986318e1d7688d1cba26d950d7ae32 Mon Sep 17 00:00:00 2001 From: Astoria Date: Sun, 23 Oct 2022 17:40:19 -0500 Subject: [PATCH] Archive => Search, refactoring --- v5.rb | 12 ++--- views/archiveFolderIndex.erb | 22 ---------- views/archivepage.erb | 44 ------------------- views/asideFolderBox.erb | 2 +- views/folderArchive.erb | 7 --- views/folderIndex.erb | 23 ---------- views/folderpage.erb | 26 ++++------- views/homeArchive.erb | 7 --- views/homeIndex.erb | 27 ------------ views/homepage.erb | 4 +- views/index.erb | 28 ++++++++++++ views/noFile.erb | 2 +- views/noFolder.erb | 2 +- views/search.erb | 7 +++ views/{archiveTopBar.erb => searchTopBar.erb} | 2 +- views/searchpage.erb | 39 ++++++++++++++++ 16 files changed, 95 insertions(+), 159 deletions(-) delete mode 100644 views/archiveFolderIndex.erb delete mode 100644 views/archivepage.erb delete mode 100644 views/folderArchive.erb delete mode 100644 views/folderIndex.erb delete mode 100644 views/homeArchive.erb delete mode 100644 views/homeIndex.erb create mode 100644 views/index.erb create mode 100644 views/search.erb rename views/{archiveTopBar.erb => searchTopBar.erb} (82%) create mode 100644 views/searchpage.erb diff --git a/v5.rb b/v5.rb index b9689e2..1bdfc4e 100755 --- a/v5.rb +++ b/v5.rb @@ -68,16 +68,16 @@ get '/news/*' do erb :blogpage end -get '/archive' do - erb :archivepage, locals: {folder: "all", searchquery: ""} +get '/search' do + erb :searchpage, locals: {folder: "all", searchquery: ""} end -get '/archive/' do - erb :archivepage, locals: {folder: "all", searchquery: ""} +get '/search/' do + erb :searchpage, locals: {folder: "all", searchquery: ""} end -get '/archive/:folder' do - erb :archivepage, locals: {folder: params["folder"].downcase, searchquery: params["search"]} +get '/search/:folder' do + erb :searchpage, locals: {folder: params["folder"].downcase, searchquery: params["search"]} end get '/about' do diff --git a/views/archiveFolderIndex.erb b/views/archiveFolderIndex.erb deleted file mode 100644 index 74f073c..0000000 --- a/views/archiveFolderIndex.erb +++ /dev/null @@ -1,22 +0,0 @@ -<% contents = Dir.children("./" + folder).grep(/#{searchquery}/) %> -<% contentsArray = Array.new %> -<% contents.each do |content| %> - <% if content.end_with?(".erb") || content.end_with?(".md") %> - <% if File.exists?("./" + folder + "/" + content + ".meta") %> - <% newPage = Page.new(content, DateTime.parse(File.read("./" + folder + "/" + content + ".meta"), "%Y.%m.%d")) %> - <% else %> - <% newPage = Page.new(content, DateTime.parse("1970.01.01", "%Y.%m.%d")) %> - <% end %> - <% contentsArray.push(newPage) %> - <% end %> -<% end %> - -<% contentsArray.sort_by! { |page| page.getdate } %> - -<% contentsArray.reverse.each do |content| %> - <% if content.getpath.end_with?(".erb") %> - <%= erb :blogpageERB, locals: {file: "./" + folder + "/" + content.getpath, date: content.getdate.strftime("%Y.%m.%d")} %> - <% elsif content.getpath.end_with?(".md") %> - <%= erb :blogpageMD, locals: {file: "./" + folder + "/" + content.getpath, date: content.getdate.strftime("%Y.%m.%d")} %> - <% end %> -<% end %> \ No newline at end of file diff --git a/views/archivepage.erb b/views/archivepage.erb deleted file mode 100644 index 3b2483a..0000000 --- a/views/archivepage.erb +++ /dev/null @@ -1,44 +0,0 @@ - - -<% if folder == "all" %> - <% doAllFolder = true %> - <% title = "Archive" %> -<% else %> - <% doAllFolder = false %> - <% title = "Archive - " + folder.capitalize %> -<% end %> - - <%= title %> - - - - - <%= erb :headerBoilerplate %> - - - <%= erb :asidemenu %> -
- <%= erb :archiveTopBar, locals: {folder: folder} %> - <%= erb :searchbar, locals: {folder: folder} %> - <% if folder == "all" %> - <% foldersOfInterest = ["media", "technology", "news"] %> - <% foldersOfInterest.each do |multiFolder| %> - <% if Dir.exist?("./" + multiFolder) %> - <% if !Dir.children("./" + multiFolder).grep(/erb/).grep(/#{searchquery}/).empty? || !Dir.children("./" + multiFolder).grep(/md/).grep(/#{searchquery}/).empty? %> - <%= erb :archiveFolderIndex, locals: {folder: multiFolder, searchquery: searchquery} %> - <% end %> - <% end %> - <% end %> - <% elsif Dir.exist?("./" + folder) %> - <% if !Dir.children("./" + folder).grep(/erb/).grep(/#{searchquery}/).empty? || !Dir.children("./" + folder).grep(/md/).grep(/#{searchquery}/).empty? %> - <%= erb :archiveFolderIndex, locals: {folder: folder, searchquery: searchquery} %> - <% else %> - <%= erb :noFile %> - <% end %> - <% else %> - <%= erb :noFolder %> - <% end %> - <%# searchquery %> -
- <%= erb :bottom %> - \ No newline at end of file diff --git a/views/asideFolderBox.erb b/views/asideFolderBox.erb index c8ff143..32706d0 100644 --- a/views/asideFolderBox.erb +++ b/views/asideFolderBox.erb @@ -1,5 +1,5 @@ <% -folders =["Media", "Technology", "News"] +folders =["Media", "Technology", "News", "Search"] %>