From e5524ffefb13024ee82c2a182b2a6a05a5f293c9 Mon Sep 17 00:00:00 2001 From: sarahcrack <73823091+sarahcrack@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:34:46 +0000 Subject: [PATCH] Remove blog tech debt (#4455) * removed blog structured data from structured data helper * deleted views/blog folder and contents * removed blog_structured_data from rspec test and deleted views/layouts/blog folder and contents * deleted BlogHelper and spec file * removed BlogController * removed controllers/blog folder which included tag_controller * removed config for blog structured data from prod and dev files * removed models/pages/blog.rb and spec file * removed references to blog in content_pages_spec file * removed blog from sitemap controller * removed blog_posting from structured data spec * removed references to blog in routes.rb * removed blog scss file and import to git * renamed images/content/blog to how-to-apply-for-teacher-training to house notepad image. Edited paths * removed references to blog in images.yml file * re-instated 2 external link redirects to routes.rb as per review comments * renamed folder containing notepad image and edited paths * removed spec/support/views/content/blog/post_invalid_tag.md and blog folder --- app/controllers/blog/tag_controller.rb | 20 -- app/controllers/blog_controller.rb | 35 ---- app/controllers/sitemap_controller.rb | 1 - app/helpers/blog_helper.rb | 15 -- app/helpers/structured_data_helper.rb | 20 -- app/models/pages/blog.rb | 55 ----- app/views/blog/_date_and_author.html.erb | 7 - app/views/blog/_header.html.erb | 5 - app/views/blog/_highlights.erb | 3 - app/views/blog/_post_preview.html.erb | 17 -- app/views/blog/_tag_list.html.erb | 5 - ...riching-the-lives-of-young-people.html.erb | 3 - app/views/blog/index.html.erb | 24 --- app/views/blog/tag/show.html.erb | 10 - .../how-to-apply-for-teacher-training.md | 2 +- app/views/layouts/blog/index.html.erb | 23 --- app/views/layouts/blog/post.html.erb | 60 ------ .../content/{blog => application}/notepad.jpg | Bin app/webpacker/styles/blog.scss | 194 ------------------ app/webpacker/styles/git.scss | 1 - config/environments/development.rb | 1 - config/environments/production.rb | 1 - config/images.yml | 77 +------ config/routes.rb | 6 - spec/features/content_pages_spec.rb | 3 +- spec/helpers/blog_helper_spec.rb | 41 ---- spec/helpers/structured_data_helper_spec.rb | 59 ------ spec/models/pages/blog_spec.rb | 114 ---------- spec/requests/structured_data_spec.rb | 2 +- .../views/content/blog/post_invalid_tag.md | 9 - 30 files changed, 7 insertions(+), 806 deletions(-) delete mode 100644 app/controllers/blog/tag_controller.rb delete mode 100644 app/controllers/blog_controller.rb delete mode 100644 app/helpers/blog_helper.rb delete mode 100644 app/models/pages/blog.rb delete mode 100644 app/views/blog/_date_and_author.html.erb delete mode 100644 app/views/blog/_header.html.erb delete mode 100644 app/views/blog/_highlights.erb delete mode 100644 app/views/blog/_post_preview.html.erb delete mode 100644 app/views/blog/_tag_list.html.erb delete mode 100644 app/views/blog/closing-paragraphs/_enriching-the-lives-of-young-people.html.erb delete mode 100644 app/views/blog/index.html.erb delete mode 100644 app/views/blog/tag/show.html.erb delete mode 100644 app/views/layouts/blog/index.html.erb delete mode 100644 app/views/layouts/blog/post.html.erb rename app/webpacker/images/content/{blog => application}/notepad.jpg (100%) delete mode 100644 app/webpacker/styles/blog.scss delete mode 100644 spec/helpers/blog_helper_spec.rb delete mode 100644 spec/models/pages/blog_spec.rb delete mode 100644 spec/support/views/content/blog/post_invalid_tag.md diff --git a/app/controllers/blog/tag_controller.rb b/app/controllers/blog/tag_controller.rb deleted file mode 100644 index 6704f1ce89..0000000000 --- a/app/controllers/blog/tag_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -class Blog::TagController < ApplicationController - include PaginatablePosts - - layout "layouts/blog/index" - - POSTS_PER_PAGE = 10 - - def show - @front_matter = { - "title" => "Blog posts about #{params[:id].tr('-', ' ')}", - "noindex" => true, - } - - breadcrumb "Blog", blog_index_path - breadcrumb @front_matter["title"], request.path - - @tag = params[:id] - @posts = paginate_posts(::Pages::Blog.posts(@tag)) - end -end diff --git a/app/controllers/blog_controller.rb b/app/controllers/blog_controller.rb deleted file mode 100644 index 76d0a06b78..0000000000 --- a/app/controllers/blog_controller.rb +++ /dev/null @@ -1,35 +0,0 @@ -class BlogController < ApplicationController - include PaginatablePosts - - caches_page :show - - layout "layouts/blog/index" - - def index - @front_matter = { - "title" => "Get Into Teaching Blog", - "description" => "Read about the real life experiences of teachers and teachers in training, as well as tips on how to start your journey into the classroom.", - } - - breadcrumb "Blog", blog_index_path - - @posts = paginate_posts(::Pages::Blog.posts) - end - - def show - @post = ::Pages::Blog.find(request.path) - - begin - @post.validate! - rescue ::Pages::ContentError => e - raise e unless helpers.display_content_errors? - - add_content_error(e) - end - - breadcrumb "Blog", blog_index_path - breadcrumb @post.title, request.path - - render template: @post.template, layout: "layouts/blog/post" - end -end diff --git a/app/controllers/sitemap_controller.rb b/app/controllers/sitemap_controller.rb index c58a00a79c..59fabb950e 100644 --- a/app/controllers/sitemap_controller.rb +++ b/app/controllers/sitemap_controller.rb @@ -11,7 +11,6 @@ class SitemapController < ApplicationController # This will keep it consistent with how canonical-rails behaves and ensure search engines are happy. OTHER_PATHS = %w[ /events - /blog /events/about-get-into-teaching-events /mailinglist/signup/name ].freeze diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb deleted file mode 100644 index dc4341f7fa..0000000000 --- a/app/helpers/blog_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -module BlogHelper - def format_blog_date(date_string) - Date.parse(date_string).to_formatted_s(:govuk_zero_pad) - end - - def thumbnail_image_from_post(images) - first_image_params = images.values.first.symbolize_keys - - if first_image_params.key?(:thumbnail_path) - first_image_params[:path] = first_image_params[:thumbnail_path] - end - - render Content::ImageComponent.new(**first_image_params.slice(:path)) - end -end diff --git a/app/helpers/structured_data_helper.rb b/app/helpers/structured_data_helper.rb index 8fada1df46..1e5f984fe8 100644 --- a/app/helpers/structured_data_helper.rb +++ b/app/helpers/structured_data_helper.rb @@ -18,26 +18,6 @@ def structured_data(type, data) end end - def blog_structured_data(page) - frontmatter = page.frontmatter - author_name = frontmatter[:author] - - data = { - headline: frontmatter[:title], - image: frontmatter[:images]&.values&.map { |h| asset_pack_url(h["path"]) }, - datePublished: frontmatter[:date], - keywords: frontmatter[:keywords], - author: [ - { - "@type": author_name.present? ? "Person" : "Organization", - name: author_name || "Get Into Teaching", - }, - ], - }.compact - - structured_data("BlogPosting", data) - end - def government_organization_structured_data data = { "@context": "https://schema.org", diff --git a/app/models/pages/blog.rb b/app/models/pages/blog.rb deleted file mode 100644 index bc11fa46d3..0000000000 --- a/app/models/pages/blog.rb +++ /dev/null @@ -1,55 +0,0 @@ -module Pages - class Blog - class InvalidTagError < RuntimeError; end - - class << self - delegate :posts, :popular_tags, :similar_posts, to: :instance - - def find(path) - ::Pages::Post.find(path) - end - - private - - def instance - new - end - end - - def initialize(pages = Pages::Frontmatter.select_by_path("/blog")) - @posts = pages - .select { |_path, fm| fm[:date] <= Time.zone.today.iso8601 } - .sort_by { |_path, fm| fm[:date] } - .reverse - .to_h - end - - def posts(tag = nil) - return @posts unless tag - - @posts.select { |_path, fm| tag.in?(fm[:tags].map(&:parameterize)) } - end - - # return the most-frequently used tags, ordered by frequency then - # alphabetically if there are ties - def popular_tags(limit = 5) - posts - .flat_map { |_path, fm| fm[:tags] } - .compact - .tally - .sort_by { |tag, count| [-count, tag] } - .map { |tag, _count| tag } - .first(limit) - end - - def similar_posts(post, limit = 3) - tags = post.frontmatter.tags - - posts - .reject { |path, _fm| path == post.path } - .sort_by { |_path, fm| -(tags & fm[:tags]).size } - .first(limit) - .to_h - end - end -end diff --git a/app/views/blog/_date_and_author.html.erb b/app/views/blog/_date_and_author.html.erb deleted file mode 100644 index 21e4472fd5..0000000000 --- a/app/views/blog/_date_and_author.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -
- Published <%= format_blog_date(front_matter["date"]) %> -
- -
- By <%= front_matter["author"] || "Get Into Teaching" %> -
diff --git a/app/views/blog/_header.html.erb b/app/views/blog/_header.html.erb deleted file mode 100644 index 1bf3962c95..0000000000 --- a/app/views/blog/_header.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -
"> -

<%= tag.span(@front_matter["title"]) %>

-

Real teachers talk about their experiences, and our experts give tips on how to get into initial teacher training.

-
-
diff --git a/app/views/blog/_highlights.erb b/app/views/blog/_highlights.erb deleted file mode 100644 index 4d278e1118..0000000000 --- a/app/views/blog/_highlights.erb +++ /dev/null @@ -1,3 +0,0 @@ -
    -
  1. <%= link_to("Applying for teacher training", blog_tag_path("applications")) %>
  2. -
diff --git a/app/views/blog/_post_preview.html.erb b/app/views/blog/_post_preview.html.erb deleted file mode 100644 index 7baa4216fc..0000000000 --- a/app/views/blog/_post_preview.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -
-
-
-

<%= link_to fm[:title], path %>

- <% if fm[:subtitle].present? %> -
<%= fm[:subtitle] %>
- <% end %> - - <%= render partial: "blog/date_and_author", locals: { front_matter: fm.with_indifferent_access } %> -
- <% if fm[:images].present? %> -

<%= thumbnail_image_from_post(fm[:images]) %>

- <% end %> -
-

<%= fm[:description] %>

- <%= render partial: "blog/tag_list", locals: { tags: fm[:tags] } %> -
diff --git a/app/views/blog/_tag_list.html.erb b/app/views/blog/_tag_list.html.erb deleted file mode 100644 index b98fe864bf..0000000000 --- a/app/views/blog/_tag_list.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -
    - <% tags.each do |tag| %> -
  1. <%= link_to(tag, blog_tag_path(tag.parameterize)) %>
  2. - <% end %> -
diff --git a/app/views/blog/closing-paragraphs/_enriching-the-lives-of-young-people.html.erb b/app/views/blog/closing-paragraphs/_enriching-the-lives-of-young-people.html.erb deleted file mode 100644 index 622da08fb8..0000000000 --- a/app/views/blog/closing-paragraphs/_enriching-the-lives-of-young-people.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

- If you're interested in enriching the lives of young people, find out more about how you can become a teacher. -

diff --git a/app/views/blog/index.html.erb b/app/views/blog/index.html.erb deleted file mode 100644 index 3b1053a04c..0000000000 --- a/app/views/blog/index.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -<%= content_for :aside do %> -
-

Popular tags

- <%= render partial: "blog/tag_list", locals: { tags: Pages::Blog.popular_tags } %> -
- -
-

Highlights

- <%= render partial: "blog/highlights" %> -
- -
-<% end %> - -
    - <% @posts.each do |post| %> -
  1. - <%= render partial: "blog/post_preview", locals: { path: post[:path], fm: post[:fm] } %> -
    -
  2. - <% end %> -
- -<%= paginate @posts, window: 2 %> diff --git a/app/views/blog/tag/show.html.erb b/app/views/blog/tag/show.html.erb deleted file mode 100644 index fb2cf0809f..0000000000 --- a/app/views/blog/tag/show.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
    - <% @posts.each do |post| %> -
  1. - <%= render partial: "blog/post_preview", locals: { path: post[:path], fm: post[:fm] } %> -
    -
  2. - <% end %> -
- -<%= paginate @posts, window: 2 %> diff --git a/app/views/content/how-to-apply-for-teacher-training.md b/app/views/content/how-to-apply-for-teacher-training.md index b55ab380f4..60318f7374 100644 --- a/app/views/content/how-to-apply-for-teacher-training.md +++ b/app/views/content/how-to-apply-for-teacher-training.md @@ -15,5 +15,5 @@ layout: "layouts/category" content: - content/how-to-apply-for-teacher-training/questions - content/how-to-apply-for-teacher-training/why-teach -image: "static/images/content/blog/notepad.jpg" +image: "static/images/content/application/notepad.jpg" --- diff --git a/app/views/layouts/blog/index.html.erb b/app/views/layouts/blog/index.html.erb deleted file mode 100644 index 754a40aaba..0000000000 --- a/app/views/layouts/blog/index.html.erb +++ /dev/null @@ -1,23 +0,0 @@ - - - <%= render "sections/head" %> - <%= body_tag do %> - <%= render "sections/govuk_javascript" %> - <%= render HeaderComponent.new(@front_matter) %> - - <%= main_tag do %> -
- <%= render(partial: "blog/header", locals: { mobile: true }) %> -
"> - <%= render(partial: "blog/header", locals: { mobile: false }) %> - <%= yield %> -
- -
- <% end %> - - <%= render FooterComponent.new %> - <% end %> - diff --git a/app/views/layouts/blog/post.html.erb b/app/views/layouts/blog/post.html.erb deleted file mode 100644 index 9856f2e360..0000000000 --- a/app/views/layouts/blog/post.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -<% content_for(:head) do %> - <%= blog_structured_data(@post) %> -<% end %> - - - - <%= render "sections/head" %> - <%= body_tag do %> - <%= render "sections/govuk_javascript" %> - <%= render HeaderComponent.new(@front_matter) %> - - <%= main_tag do %> -
- <%= render(partial: "sections/content_errors") %> - -
-
- <%= tag.h1(@front_matter["title"], class: "heading-l heading--margin-bottom-0") %> - <% if @front_matter.key?("subtitle") %> - <%= tag.div(@front_matter["subtitle"], role: 'doc-subtitle') %> - <% end %> - - <%= render partial: "blog/date_and_author", locals: { front_matter: @front_matter } %> -
- - <%= yield %> - - <% if @front_matter.key?("closing_paragraph") %> - <%= render(partial: %(blog/closing-paragraphs/#{@front_matter['closing_paragraph']})) %> - <% end %> - -
- - -
-
- - <% if @front_matter.key?("promo_content") %> - <% @front_matter["promo_content"]&.each do |partial| %> - <%= render(partial) %> - <% end %> - <% end %> - <% end %> - - <%= render FooterComponent.new %> - <% end %> - diff --git a/app/webpacker/images/content/blog/notepad.jpg b/app/webpacker/images/content/application/notepad.jpg similarity index 100% rename from app/webpacker/images/content/blog/notepad.jpg rename to app/webpacker/images/content/application/notepad.jpg diff --git a/app/webpacker/styles/blog.scss b/app/webpacker/styles/blog.scss deleted file mode 100644 index 978e8732b8..0000000000 --- a/app/webpacker/styles/blog.scss +++ /dev/null @@ -1,194 +0,0 @@ -@mixin blog-article { - @include mq($from: tablet) { - > div { - display: flex; - gap: $indent-amount; - - header { - flex-grow: 1; - } - } - } - - header { - .published-date { - margin-top: $indent-amount; - } - } -} - -.blog { - hr, - header p { - margin-top: 2 * $indent-amount; - } - - header + p { - margin-top: 3em; - } - - ol { - padding-left: 0; - } - - aside { - padding: 0 $indent-amount; - - @include mq($from: tablet) { - padding: 0; - - hr { - display: none; - } - } - - > div { - margin-bottom: $indent-amount; - } - - .blog-highlights { - list-style: none; - - li { - margin-top: .4em; - } - } - } - - .blog-tags { - display: flex; - flex-wrap: wrap; - grid-gap: .8em; - gap: .8em; - margin: 0; - list-style: none; - - li { - background-color: $grey; - margin-bottom: 0; - - &:last-child { - margin-bottom: 0; - } - - a { - display: block; - padding: .4em .8em; - @extend .link--dark; - } - } - } - - .blog-index { - margin-top: 0; - list-style: none; - - li > .blog-article { - @include blog-article; - - img { - width: 170px; - height: 120px; - object-fit: cover; - object-position: center; - } - } - - li:last-child hr { - display: none; - } - } - - > .blog-article { - @include blog-article; - - > p:last-of-type { - border-left: .4em solid $grey-mid; - padding: .5em 0 .5em 1em; - margin-top: 2.5em; - } - - img { - width: 100%; - height: 300px; - object-position: center; - object-fit: cover; - - @include mq($from: mobile) { - height: 450px; - } - - @include mq($from: desktop) { - height: 550px; - } - } - } - - blockquote { - margin: 2em 1.5rem; - - @include quote($white); - - border-left: 5px solid $pink; - - p { - margin: 0; - padding: 0 1em 1em 1.5em; - font-weight: normal; - - span { - white-space: nowrap; - font-weight: normal; - } - - // some extra rules to make the quotes a bit nicer. this 'smart' css - // unfortunately has the side affect of requiring attribution for - // multi-paragraph quotes; to get around it we'll need to implement - // something more powerful like the regular quote module that wraps - // the
in a
with a
- - &::before, - &::after { - color: $black; - } - - // always open the quote on the first paragraph - &:first-child { - &::before { - content: '"'; - } - } - - // close the quote on the only paragraph (if there's no attribution) - // or the second last if there is - &:nth-last-child(2), - &:only-of-type { - &::after { - content: '"'; - } - padding-bottom: 0; - } - - // if we have more than one paragraph make the last one the attribution - &:last-child:not(:only-of-type) { - display: block; - font-style: normal; - font-weight: bold; - margin-top: 1em; - margin-bottom: 0; - padding-bottom: 0; - } - } - } - - @include mq($from: tablet) { - .text-content.longform { - padding-right: 1.5em; - box-sizing: border-box; - - &.with-aside { - border-right: 1px solid $grey-mid; - } - } - } -} diff --git a/app/webpacker/styles/git.scss b/app/webpacker/styles/git.scss index 8135f41ef7..387804900d 100644 --- a/app/webpacker/styles/git.scss +++ b/app/webpacker/styles/git.scss @@ -22,7 +22,6 @@ @import "blocks"; @import "search-page"; @import "steps"; -@import "blog"; @import "welcome-guide"; @import "category"; @import "statement"; diff --git a/config/environments/development.rb b/config/environments/development.rb index 49f741adf6..4047020697 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -62,7 +62,6 @@ config.x.basic_auth = ENV["BASIC_AUTH"] - config.x.structured_data.blog_posting = true config.x.structured_data.web_site = true config.x.structured_data.organization = true config.x.structured_data.government_organization = true diff --git a/config/environments/production.rb b/config/environments/production.rb index cfcc92a703..fac259c327 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -133,7 +133,6 @@ level: Rails.application.config.log_level, formatter: config.rails_semantic_logger.format - config.x.structured_data.blog_posting = false config.x.structured_data.web_site = true config.x.structured_data.organization = false config.x.structured_data.government_organization = true diff --git a/config/images.yml b/config/images.yml index b034693847..786e9a8071 100644 --- a/config/images.yml +++ b/config/images.yml @@ -221,85 +221,18 @@ - "static/images/content/hero-images/physics_1383-mobile.jpg" - "static/images/content/hero-images/physics_1383-tablet.jpg" -# blog +# case studies "static/images/content/case-studies/abigail.jpg": alt: "Maths teacher Abigail in front of a maths display board." "static/images/content/case-studies/ben.jpg": alt: "Maths and science teacher Ben marking work at home." -"static/images/content/blog/applying-for-teacher.jpg": +# how to apply for teacher training +"static/images/content/application/notepad.jpg": alt: "" variants: - - "static/images/content/blog/thumbnails/applying-for-teacher.jpg" - -"static/images/content/blog/calculator.jpg": - # A calculator on top of maths homework and a pencil case. - alt: "" - variants: - - "static/images/content/blog/thumbnails/calculator.jpg" - -"static/images/content/blog/interview.jpg": - # A teacher training candidate being interviewed by a provider sitting at opposite sides of a desk. - alt: "" - variants: - - "static/images/content/blog/thumbnails/interview.jpg" - -"static/images/content/blog/mel-stta-screen.jpg": - alt: "Conference room with tables and a projector for a Sheffield Teacher Training Alliance PGDE course." - variants: - - "static/images/content/blog/thumbnails/mel-stta-screen.jpg" - -"static/images/content/blog/notepad.jpg": - alt: "" - variants: - - "static/images/content/blog/thumbnails/notepad.jpg" - -"static/images/content/blog/right_provider.jpg": - alt: "" - variants: - - "static/images/content/blog/thumbnails/right_provider.jpg" - -"static/images/content/blog/school-aisle.jpg": - # The corridor of a school filled with children. - alt: "" - variants: - - "static/images/content/blog/thumbnails/school-aisle.jpg" - -"static/images/content/blog/schoolyard.jpg": - # A school playground with secondary school children playing outdoors. - alt: "" - variants: - - "static/images/content/blog/thumbnails/schoolyard.jpg" - -"static/images/content/blog/seminar-room.jpg": - # PGCE lecturer at a whiteboard in a seminar room with teacher training students sitting at a table. - alt: "" - variants: - - "static/images/content/blog/thumbnails/seminar-room.jpg" - -"static/images/content/blog/get-into-teaching.jpg": - # A busy Get Into Teaching event with attendees having conversations with Teacher Training Advisers. - alt: "" - variants: - - "static/images/content/blog/thumbnails/get-into-teaching.jpg" - -"static/images/content/blog/whiteboard.jpg": - alt: "" - variants: - - "static/images/content/blog/thumbnails/whiteboard.jpg" - -"static/images/content/blog/thumbnails/stories-zainab.jpg": - alt: "Zainab Kasmani, English teacher" - -"static/images/content/blog/thumbnails/stories-sarah-f.jpg": - alt: "Sarah Fisher, head of biology" - -"static/images/content/blog/thumbnails/stories-generic.jpg": - alt: "Students enjoying a lesson in a classroom" - -"static/images/content/blog/thumbnails/stories-katie.jpg": - alt: "Head of faculty, Katie Lockett" + - "static/images/content/application/thumbnails/notepad.jpg" # homepage "static/images/content/homepage/here-to-help.jpg": @@ -399,5 +332,3 @@ # subjects "static/images/content/subjects/rotna-roy.jpeg": alt: "Rotna, maths teacher" - - diff --git a/config/routes.rb b/config/routes.rb index e1819dcb7e..9c34e6cbe0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,12 +96,6 @@ resource :csp_reports, only: %i[create] resource :client_metrics, only: %i[create] - resources :blog, controller: "blog", only: %i[index show] do - collection do - resources :tag, only: %i[show], as: :blog_tag, controller: "blog/tag" - end - end - resources "teaching_events", as: "events", path: "/events", controller: "teaching_events" do collection do get :about_git_events, path: "about-get-into-teaching-events", as: "about_git" diff --git a/spec/features/content_pages_spec.rb b/spec/features/content_pages_spec.rb index 1b501d1e5a..3d2fc08082 100644 --- a/spec/features/content_pages_spec.rb +++ b/spec/features/content_pages_spec.rb @@ -13,7 +13,7 @@ def initialize(path, status_code, body) RSpec.feature "content pages check", :content, type: :feature do include Values - let(:other_paths) { %w[/ /feedback /blog /blog/post_invalid_tag /search /teacher-training-adviser/sign_up/identity /mailinglist/signup /mailinglist/signup/name /cookies /cookie_preference /chat] } + let(:other_paths) { %w[/ /feedback /search /teacher-training-adviser/sign_up/identity /mailinglist/signup /mailinglist/signup/name /cookies /cookie_preference /chat] } let(:ignored_path_patterns) { [%r{/assets/documents/}, %r{/event-categories}, %r{/test}] } before do @@ -132,7 +132,6 @@ def css_to_xpath(css_selector) .map { |fragment| fragment["href"] } .reject(&:nil?) .reject { |href| href.start_with?(Regexp.union("http:", "https:", "tel:", "mailto:")) } - .reject { |href| href.start_with?("/blog/tag") } .reject { |href| href.start_with?("/chat") } .reject { |href| href.match?("static/") } .reject { |href| href.match?(Regexp.union("privacy-policy", "events", "javascript", "browse")) } diff --git a/spec/helpers/blog_helper_spec.rb b/spec/helpers/blog_helper_spec.rb deleted file mode 100644 index f670ca7fd2..0000000000 --- a/spec/helpers/blog_helper_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "rails_helper" - -describe BlogHelper, type: "helper" do - describe "#format_blog_date" do - subject { format_blog_date(markdown_date) } - - let(:markdown_date) { "2019-03-04" } - - specify "formats the date in the GOV.UK short style" do - expect(subject).to eql("4 March 2019") - end - end - - describe "#thumbnail_image_from_post" do - let(:image_component) { class_double(Content::ImageComponent).as_stubbed_const } - let(:images) do - { - "first" => { "path" => "one.jpg" }, - "second" => { "path" => "two.jpg" }, - } - end - - specify "initializes an Content::ImageComponent with the attributes from the first image" do - expect(image_component).to receive(:new).with(path: "one.jpg").and_return(inline: "doesn't matter") - - thumbnail_image_from_post(images) - end - - context "when the first image has a thumbnail_path" do - before do - images["first"]["thumbnail_path"] = "thumbnail.jpg" - end - - specify "initializes an Content::ImageComponent with the thumbnail_path" do - expect(image_component).to receive(:new).with(path: "thumbnail.jpg").and_return(inline: "doesn't matter") - - thumbnail_image_from_post(images) - end - end - end -end diff --git a/spec/helpers/structured_data_helper_spec.rb b/spec/helpers/structured_data_helper_spec.rb index 966649012b..aacaaeebf6 100644 --- a/spec/helpers/structured_data_helper_spec.rb +++ b/spec/helpers/structured_data_helper_spec.rb @@ -46,65 +46,6 @@ end end - describe ".blog_structured_data" do - subject(:data) { JSON.parse(script_tag.content, symbolize_names: true) } - - let(:frontmatter) do - { - title: "A title", - images: { - an_image: { - "path" => image_path, - }, - }, - date: "2021-01-25", - keywords: %w[one two], - author: "Ronald McDonald", - } - end - let(:page) { ::Pages::Page.new("/blog/post", frontmatter) } - let(:html) { blog_structured_data(page) } - let(:script_tag) { Nokogiri::HTML.parse(html).at_css("script") } - - before { enable_structured_data(:blog_posting) } - - it "returns nil when disabled by config" do - disable_structured_data(:blog_posting) - expect(script_tag).to be_nil - end - - it "includes blog post information" do - expect(data).to include({ - "@type": "BlogPosting", - headline: frontmatter[:title], - image: frontmatter[:images].values.map { |h| asset_pack_url(h["path"]) }, - datePublished: frontmatter[:date], - keywords: frontmatter[:keywords], - author: [ - { - "@type": "Person", - name: frontmatter[:author], - }, - ], - }) - end - - context "when author is not present" do - before { frontmatter[:author] = nil } - - it "defaults to the Get Into Teaching organization" do - expect(data).to include({ - author: [ - { - "@type": "Organization", - name: "Get Into Teaching", - }, - ], - }) - end - end - end - describe ".government_organization_structured_data" do subject(:data) { JSON.parse(script_tag.content, symbolize_names: true) } diff --git a/spec/models/pages/blog_spec.rb b/spec/models/pages/blog_spec.rb deleted file mode 100644 index 3a79f143ca..0000000000 --- a/spec/models/pages/blog_spec.rb +++ /dev/null @@ -1,114 +0,0 @@ -require "rails_helper" - -RSpec.describe Pages::Blog do - let(:pages) do - { - # 5*january 4*february, 3*march, 2*april, 1*may - a: { date: "2019-01-01", tags: %w[january february march april may] }, - b: { date: "2019-01-01", tags: %w[january february march april] }, - c: { date: "2019-01-01", tags: %w[january february march] }, - d: { date: "2019-01-01", tags: %w[january february] }, - e: { date: "2019-01-01", tags: %w[january] }, - - # 4*june, 3*july, 2*august, 1*september - f: { date: "2019-01-01", tags: %w[june july august september] }, - g: { date: "2019-01-01", tags: %w[june july august] }, - h: { date: "2019-01-01", tags: %w[june july] }, - i: { date: "2019-01-01", tags: %w[june] }, - } - end - - describe ".find" do - subject { described_class } - - before { allow(::Pages::Post).to receive(:find).with("/some/template").and_return("/some_template.md") } - - specify "calls the other method" do - described_class.find("/some/template") - - expect(::Pages::Post).to have_received(:find).with("/some/template").once - end - end - - describe "#posts" do - describe "retrieves pages in blog directory by default" do - subject { described_class.new } - - specify "there is at least one blog post" do - expect(subject.posts.size).to be >= 1 - end - - specify "all posts are in the blog directory" do - expect(subject.posts.keys).to all(start_with("/blog")) - end - end - - context "when filtering by a single tag" do - subject { described_class.new(pages) } - - let(:wanted_tag) { "august" } - - specify "return the right number of posts" do - expect(subject.posts(wanted_tag).size).to be 2 - end - - specify "all returned posts have the right tag" do - tags_per_post = subject.posts(wanted_tag).map { |_p, fm| fm[:tags] } - - expect(tags_per_post).to all(include(wanted_tag)) - end - end - end - - describe "#popular_tags" do - subject { described_class.new(pages).popular_tags } - - specify "orders by frequency then alphabetically" do - expect(subject).to eql(%w[january february june july march]) - end - - context "with a custom limit" do - subject { described_class.new(pages).popular_tags(7) } - - specify "orders by frequency then alphabetically" do - expect(subject).to eql(%w[january february june july march april august]) - end - end - end - - describe "#similar_posts" do - subject { described_class.new(pages).similar_posts(origin) } - - let(:origin_tags) { %w[june july] } - let(:origin_path) { :f } - let(:origin_fm) { OpenStruct.new(tags: origin_tags) } - let(:origin) { OpenStruct.new(path: origin_path, frontmatter: origin_fm) } - - specify "returns pages that have overlapping tags" do - tags = subject.values.map { |fm| fm[:tags] } - - tags.each do |tags_per_similar_post| - expect((tags_per_similar_post & origin_tags).size).to be > 0 - end - end - - specify "orders by the number of overlapping tags" do - # :i has one overlap (june), :g and :h are have two - expect(subject.keys.last).to be(:i) - end - - specify "does not include the original post" do - expect(subject.keys).not_to include(origin_path) - end - - context "when a limit is applied" do - subject { described_class.new(pages).similar_posts(origin, limit) } - - let(:limit) { 2 } - - specify "only the right number of posts are returned" do - expect(subject.size).to be(limit) - end - end - end -end diff --git a/spec/requests/structured_data_spec.rb b/spec/requests/structured_data_spec.rb index 665d497846..0ec6b9426d 100644 --- a/spec/requests/structured_data_spec.rb +++ b/spec/requests/structured_data_spec.rb @@ -7,7 +7,7 @@ let(:json_contents) { parsed_response.css("script[type='application/ld+json']").map(&:content) } before do - %i[event blog_posting organization breadcrumb_list web_site].each do |type| + %i[event organization breadcrumb_list web_site].each do |type| allow(Rails.application.config.x.structured_data).to \ receive(type).and_return(true) end diff --git a/spec/support/views/content/blog/post_invalid_tag.md b/spec/support/views/content/blog/post_invalid_tag.md deleted file mode 100644 index 22c4521190..0000000000 --- a/spec/support/views/content/blog/post_invalid_tag.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: A blog post with invalid tag -subtitle: A blog post with invalid tag -date: "2022-05-17" -tags: - - invalid tag ---- - -A blog post with invalid tag