diff --git a/app/browse.rb b/app/browse.rb index ab195b9b..1b9c5c4e 100644 --- a/app/browse.rb +++ b/app/browse.rb @@ -1,6 +1,16 @@ get '/browse/?' do + @current_page = params[:current_page] + @current_page = @current_page.to_i + @current_page = 1 if @current_page == 0 + params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty? - site_dataset = browse_sites_dataset + + if is_education? + site_dataset = education_sites_dataset + else + site_dataset = browse_sites_dataset + end + site_dataset = site_dataset.paginate @current_page, Site::BROWSE_PAGINATION_LENGTH @page_count = site_dataset.page_count || 1 @sites = site_dataset.all @@ -10,11 +20,14 @@ get '/browse/?' do erb :browse end -def browse_sites_dataset - @current_page = params[:current_page] - @current_page = @current_page.to_i - @current_page = 1 if @current_page == 0 +def education_sites_dataset + site_dataset = Site.filter is_deleted: false + site_dataset = site_dataset.association_join(:tags).select_all(:sites) + params[:tag] = current_site.tags.first.name + site_dataset.where! ['tags.name = ?', params[:tag]] +end +def browse_sites_dataset site_dataset = Site.filter(is_deleted: false, is_banned: false, is_crashing: false).filter(site_changed: true) if current_site diff --git a/app/index.rb b/app/index.rb index eb7ec230..6d113dfa 100644 --- a/app/index.rb +++ b/app/index.rb @@ -2,6 +2,8 @@ get '/?' do if current_site require_login + redirect '/dashboard' if current_site.is_education + @suggestions = current_site.suggestions @current_page = params[:current_page].to_i diff --git a/app/site.rb b/app/site.rb index 4f019533..7e6654f0 100644 --- a/app/site.rb +++ b/app/site.rb @@ -9,6 +9,8 @@ get '/site/:username/?' do |username| # TODO: There should probably be a "this site was deleted" page. not_found if site.nil? || site.is_banned || site.is_deleted + redirect '/' if site.is_education + @title = site.title @current_page = params[:current_page] diff --git a/app_helpers.rb b/app_helpers.rb index 7a1ea067..44f58907 100644 --- a/app_helpers.rb +++ b/app_helpers.rb @@ -15,6 +15,10 @@ def csrf_token session[:_csrf_token] ||= SecureRandom.base64(32) end +def is_education? + current_site && current_site.is_education +end + def require_login redirect '/' unless signed_in? if session[:banned] || current_site.is_banned || parent_site.is_banned diff --git a/tests/acceptance/education_tests.rb b/tests/acceptance/education_tests.rb index 449890ca..27f5276b 100644 --- a/tests/acceptance/education_tests.rb +++ b/tests/acceptance/education_tests.rb @@ -30,7 +30,7 @@ describe 'signup' do it 'succeeds with valid data' do fill_in_valid click_button 'Create My Site' - page.must_have_content 'Welcome to Neocities' + page.must_have_content /Welcome to your new site/ index_file_path = File.join Site::SITE_FILES_ROOT, @site[:username], 'index.html' File.exist?(index_file_path).must_equal true diff --git a/views/_footer.erb b/views/_footer.erb index d3409177..cd67fe04 100644 --- a/views/_footer.erb +++ b/views/_footer.erb @@ -10,9 +10,11 @@