1
0
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:
2020-05-02 20:18:04 +02:00
parent 3e85290fc6
commit 38633d6e79
21 changed files with 178 additions and 72 deletions

View 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