mirror of
https://github.com/projekteuler/projekteuler.git
synced 2026-01-27 10:38:50 +01:00
Prefill original title and content from projecteuler.net
This commit is contained in:
21
app/jobs/pull_problem_content_job.rb
Normal file
21
app/jobs/pull_problem_content_job.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'open-uri'
|
||||
|
||||
class PullProblemContentJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(problem)
|
||||
html = URI.open("https://projecteuler.net/minimal=#{problem.id}").read
|
||||
html.strip!
|
||||
|
||||
# Linked problems
|
||||
html.gsub!('<a href="problem=', '<a href="/problem=')
|
||||
# Linked about pages
|
||||
html.gsub!('<a href="about=', '<a href="/about=')
|
||||
# Linked txt resources
|
||||
html.gsub!('<a href="project/resources/', '<a href="https://projecteuler.net/project/resources/')
|
||||
# Included images
|
||||
html.gsub!('<img src="project/images/', '<img src="https://projecteuler.net/project/images/')
|
||||
|
||||
problem.update(original_content: html, pulled_at: Time.current())
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user