Skip to content

Commit

Permalink
Merge branch 'master' into master-legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
thatandromeda committed Jan 28, 2020
2 parents be458c9 + af85dfa commit 81c1c6f
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). It uses [CalVer](https://calver.org/) as of May 2019.

## [20.01a](https://github.com/berkmancenter/lumendatabase/releases/tag/2020.01a) - 2020-01-21
### Added
* We have a CMS! (Comfortable-Mexican-Sofa)
* Rake tasks to stand up the CMS and migrate blog content

## [20.01](https://github.com/berkmancenter/lumendatabase/releases/tag/2020.01) - 2020-01-08
### Changed
* Upgrade rails_admin from 1.4 to 2.0
Expand Down
19 changes: 0 additions & 19 deletions app/helpers/comfy/comfy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,4 @@ def blog_posts(cms_site)
Kaminari.paginate_array(scope.to_a, total_count: scope.count)
.page(params[:page]).per(10)
end

def fragment_title(page)
if (title = page.fragments.find_by_identifier('title').content).empty?
title = '(No title)'
end
# This can't return an empty string. Since we use the title to construct
# links to the blog post, there must be something to click on.
title
end

def fragment_content(page)
page.fragments.find_by_identifier('content').content
end

def fragment_abstract(page)
page.fragments.find_by_identifier('abstract').content
rescue NoMethodError
nil
end
end
4 changes: 2 additions & 2 deletions app/views/blog_entries/_comfy_entry.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<article class="post-item">
<h3 class="title">
<% if blog_entry.full_path.present? %>
<%= link_to(fragment_title(blog_entry), "/cms#{blog_entry.full_path}") %>
<%= link_to(cms_fragment_content('title', blog_entry), "/cms#{blog_entry.full_path}") %>
<% end %>
</h3>
<%= render 'blog_entries/comfy_metadata', blog_entry: blog_entry %>
<a class="snippet" href="<%= blog_entry.full_path %>">
<%= raw fragment_abstract(blog_entry) %>
<%= raw cms_fragment_content('abstract', blog_entry) %>
</a>
</article>
9 changes: 9 additions & 0 deletions app/views/cms_pages/_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% title cms_fragment_content('page_title', @cms_page) %>

<div class="high_voltage-pages">
<section class="main">
<div class="main-inner">
<%= raw cms_fragment_content('page_content', @cms_page) %>
</div>
</section>
</div>
2 changes: 2 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'uglifier'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
53 changes: 52 additions & 1 deletion lib/tasks/lumen.rake
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,64 @@ where works.id in (
puts "#{date_time_task.call} Finishing the task"
end

desc 'Retain OriginalNewsId URLs in CMS'
task migrate_original_news_id_redirects: :environment do
# Find Site & Layout. ------------------------------------------------------
site = Comfy::Cms::Site.find_by_identifier('lumen_cms')
layout = Comfy::Cms::Layout.first

unless site.present? && layout.present?
$stdout.puts 'lumen_cms Site, and any Layout, must be defined before running this task'
exit
end

# Find or create parent for namespacing. -----------------------------------
parent = if (page = Comfy::Cms::Page.find_by_slug('original_news_id')).present?
page
else
Comfy::Cms::Page.create(
site: site,
layout: layout,
label: 'original news ID parent',
slug: 'original_news_id',
is_published: false
)
end

# Create pages to preserve redirects. --------------------------------------
count = 0
BlogEntry.where.not(original_news_id: nil).each do |entry|
next if Comfy::Cms::Page.where(
parent: parent,
slug: entry.original_news_id
).present?

unless Comfy::Cms::Page.find_by_slug(entry.id)
puts 'Must migrate blog entries before running this task'
raise
end

Comfy::Cms::Page.create(
site: site,
layout: layout,
parent: parent,
label: "redirect_#{entry.original_news_id}",
slug: entry.original_news_id,
target_page: Comfy::Cms::Page.find_by_slug(entry.id)
)
count += 1
end

$stdout.puts "#{count} pages created"
end

desc 'Migrate BlogEntries to CMS'
task migrate_blog_entries_to_cms: :environment do
site = Comfy::Cms::Site.find_by_identifier('lumen_cms')
layout = Comfy::Cms::Layout.find_by_label('blawg')
parent = Comfy::Cms::Page.find_by_label('blog_entries')

unless site && layout && parent
unless site.present? && layout.present? && parent.present?
$stdout.puts 'lumen_cms Site, blawg Layout, and blog_entries Page must be defined before running this task'
exit
end
Expand Down
8 changes: 6 additions & 2 deletions spec/lib/tasks/blog_import_to_cms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
image: 'overcast',
content: 'content goes here'
)
Rake::Task['lumen:set_up_cms'].invoke
Rake::Task['lumen:migrate_blog_entries_to_cms'].invoke
Rake::Task['lumen:set_up_cms'].execute
Rake::Task['lumen:migrate_blog_entries_to_cms'].execute
end

after(:all) do
BlogEntry.destroy_all
end

let(:blog_parent) { Comfy::Cms::Page.find_by_label('blog_entries') }
Expand Down
38 changes: 38 additions & 0 deletions spec/lib/tasks/migrate_original_news_ids_to_cms_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'rails_helper'
require 'uri'

describe 'lumen:migrate_original_news_id_redirects', type: :request do
before(:all) do
expect(BlogEntry.count).to eq 0
create(
:blog_entry,
author: 'John Rock',
title: 'Speech at Faneuil Hall',
abstract: 'abstract goes here',
image: 'overcast',
content: 'content goes here',
original_news_id: 1
)
Rake::Task['lumen:set_up_cms'].execute
Rake::Task['lumen:migrate_blog_entries_to_cms'].execute
Rake::Task['lumen:migrate_original_news_id_redirects'].execute
end

after(:all) do
BlogEntry.destroy_all
end

it 'creates redirects for original news IDs' do
get '/original_news_id/1'
original_path = URI::parse(response.location).path

page = Comfy::Cms::Page.find_by_full_path('/original_news_id/1')
expect(page.target_page).to be_present

# The full URL will not be the same because of namespacing under the CMS.
# This is good -- it means we're not inadvertently testing our existing
# controller. But the Comfy::Cms::Page.full_path attribute does not include
# the namespacing.
expect(page.target_page.full_path).to eq original_path
end
end

0 comments on commit 81c1c6f

Please sign in to comment.