From 0ad91dad0abf550a60a7aae61395ed59423da711 Mon Sep 17 00:00:00 2001 From: Astoria Date: Sat, 22 Oct 2022 11:04:09 -0500 Subject: [PATCH] Search update. --- v5.rb | 10 +++++++- views/archiveFolderIndex.erb | 18 +++++++++++++++ views/archiveTopBar.erb | 11 +++++++++ views/archivepage.erb | 44 ++++++++++++++++++++++++++++++++++++ views/blogpageERB.erb | 2 +- views/blogpageMD.erb | 2 +- views/folderArchive.erb | 7 ++++++ views/folderpage.erb | 2 ++ views/homeArchive.erb | 7 ++++++ views/homepage.erb | 1 + views/noFile.erb | 2 +- views/noFolder.erb | 1 - views/searchbar.erb | 7 ++++++ 13 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 views/archiveFolderIndex.erb create mode 100644 views/archiveTopBar.erb create mode 100644 views/archivepage.erb create mode 100644 views/folderArchive.erb create mode 100644 views/homeArchive.erb create mode 100644 views/searchbar.erb diff --git a/v5.rb b/v5.rb index aef9425..2366a2f 100644 --- a/v5.rb +++ b/v5.rb @@ -46,7 +46,15 @@ get '/news/*' do end get '/archive' do - erb :archivepage + erb :archivepage, locals: {folder: "all", searchquery: ""} +end + +get '/archive/' do + erb :archivepage, locals: {folder: "all", searchquery: ""} +end + +get '/archive/:folder' do + erb :archivepage, locals: {folder: params["folder"].downcase, searchquery: params["search"]} end get '/about' do diff --git a/views/archiveFolderIndex.erb b/views/archiveFolderIndex.erb new file mode 100644 index 0000000..0720e11 --- /dev/null +++ b/views/archiveFolderIndex.erb @@ -0,0 +1,18 @@ +<% contents = Dir.children("./" + folder).grep(/#{searchquery}/) %> +<% contents.each do |content| %> + <% if content.end_with?(".erb") %> + <% file = content %> + <% if File.exists?("./" + folder + "/" + file + ".meta") %> + <%= erb :blogpageERB, locals: {file: "./" + folder + "/" + content, meta: "./" + folder + "/" + file + ".meta"} %> + <% else %> + <%= erb :blogpageERB, locals: {file: "./" + folder+ "/" + content} %> + <% end %> + <% elsif content.end_with?(".md") %> + <% file = content %> + <% if File.exists?("./" + folder + "/" + file + ".meta") %> + <%= erb :blogpageMD, locals: {file: "./" + folder + "/" + content, meta: "./" + folder + "/" + file + ".meta"} %> + <% else %> + <%= erb :blogpageMD, locals: {file: "./" + folder + "/" + content} %> + <% end %> + <% end %> +<% end %> \ No newline at end of file diff --git a/views/archiveTopBar.erb b/views/archiveTopBar.erb new file mode 100644 index 0000000..da983d9 --- /dev/null +++ b/views/archiveTopBar.erb @@ -0,0 +1,11 @@ +
+ + + Home + > + Archive + > + <%=folder.capitalize %> + + +
\ No newline at end of file diff --git a/views/archivepage.erb b/views/archivepage.erb new file mode 100644 index 0000000..3b2483a --- /dev/null +++ b/views/archivepage.erb @@ -0,0 +1,44 @@ + + +<% 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/blogpageERB.erb b/views/blogpageERB.erb index c3a44ba..16f96ee 100644 --- a/views/blogpageERB.erb +++ b/views/blogpageERB.erb @@ -6,6 +6,6 @@ <%= File.read(meta) %> <% end %> - Article Page + Article Page \ No newline at end of file diff --git a/views/blogpageMD.erb b/views/blogpageMD.erb index 7ca8da7..e942baa 100644 --- a/views/blogpageMD.erb +++ b/views/blogpageMD.erb @@ -6,6 +6,6 @@ <%= File.read(meta) %> <% end %> - Article Page + Article Page \ No newline at end of file diff --git a/views/folderArchive.erb b/views/folderArchive.erb new file mode 100644 index 0000000..2abb05f --- /dev/null +++ b/views/folderArchive.erb @@ -0,0 +1,7 @@ +
+ + Search <%= title %> Posts + + +
\ No newline at end of file diff --git a/views/folderpage.erb b/views/folderpage.erb index 5285248..9ec49a8 100644 --- a/views/folderpage.erb +++ b/views/folderpage.erb @@ -23,10 +23,12 @@ <% end %> <%= erb :folderIndex %> + <%= erb :folderArchive, locals: {folder: request.path_info, title: title} %> <% else %> <%= erb :noFile %> <% end %> <% else %> + <%= erb :topbar %> <%= erb :noFolder %> <% end %> diff --git a/views/homeArchive.erb b/views/homeArchive.erb new file mode 100644 index 0000000..09dd34d --- /dev/null +++ b/views/homeArchive.erb @@ -0,0 +1,7 @@ +
+ + Search All Posts + + +
\ No newline at end of file diff --git a/views/homepage.erb b/views/homepage.erb index 3cc4b8d..7ec77b2 100644 --- a/views/homepage.erb +++ b/views/homepage.erb @@ -13,6 +13,7 @@
<%= erb :homeImage %> <%= erb :homeIndex %> + <%= erb :homeArchive %>
<%= erb :bottom %> \ No newline at end of file diff --git a/views/noFile.erb b/views/noFile.erb index 521340f..2c7ff10 100644 --- a/views/noFile.erb +++ b/views/noFile.erb @@ -1,4 +1,3 @@ -<%= erb :topbar %>
\ No newline at end of file diff --git a/views/noFolder.erb b/views/noFolder.erb index 1ea6115..dd5bfd2 100644 --- a/views/noFolder.erb +++ b/views/noFolder.erb @@ -1,4 +1,3 @@ -<%= erb :topbar %>