Skip to content

Commit b3f7eaa

Browse files
committedMar 13, 2020
Stop truncating posts table for all rake tasks.
Not needed for a context fetch!
1 parent 30f2f4b commit b3f7eaa

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎Rakefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Dotenv.load
1212
require_relative 'lib/transformative.rb'
1313

1414
DB = Sequel.connect(ENV['DATABASE_URL'])
15-
DB[:posts].truncate
1615

1716
CONTENT_PATH = "#{File.dirname(__FILE__)}/../content"
1817

@@ -28,13 +27,15 @@ end
2827

2928
desc "Rebuild database cache from all content JSON files."
3029
task :rebuild do
30+
DB[:posts].truncate
3131
Dir.glob("#{CONTENT_PATH}/**/*.json").each do |file|
3232
parse(file)
3333
end
3434
end
3535

3636
desc "Rebuild database cache from this month's content JSON files."
3737
task :recent do
38+
DB[:posts].truncate
3839
year_month = Time.now.strftime('%Y/%m')
3940
files = Dir.glob("#{CONTENT_PATH}/#{year_month}/**/*.json")
4041
# need to rebuild all cites and cards because they're not organised by month

‎lib/transformative/context.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ def parse_mf2(url)
4242
published = properties.key?('published') ?
4343
Time.parse(properties['published'][0]) : Time.now
4444
post_url = properties.key?('url') ? properties['url'][0] : url
45+
post_name = properties.key?('name') ? properties['name'][0].strip : ''
4546
hash = {
4647
'url' => [URI.join(url, post_url).to_s],
47-
'name' => [properties['name'][0].strip],
48+
'name' => [post_name],
4849
'published' => [published.utc.iso8601],
4950
'content' => [properties['content'][0]['value']],
5051
'author' => [author.properties['url'][0]]

0 commit comments

Comments
 (0)
Please sign in to comment.