Lofter: add support for another theme

This commit is contained in:
nonamethanks
2021-07-12 19:07:52 +02:00
committed by evazion
parent 716b9a5b88
commit bb4bdefc23
2 changed files with 11 additions and 6 deletions

View File

@@ -11,6 +11,7 @@
# #
# * https://gengar563.lofter.com/post/1e82da8c_1c98dae1b # * https://gengar563.lofter.com/post/1e82da8c_1c98dae1b
# * https://yuli031458.lofter.com/post/3163d871_1cbdc5f6d (different theme/css selectors) # * https://yuli031458.lofter.com/post/3163d871_1cbdc5f6d (different theme/css selectors)
# * https://ssucrose.lofter.com/post/1d30f3e4_1cc58e9f0 (another different theme)
# #
# Profile URLs # Profile URLs
# #
@@ -46,7 +47,7 @@ module Sources
end end
def image_urls def image_urls
images = page&.search(".pic img, .content img") images = page&.search(".imgclasstag img")
images.to_a.map { |img| get_full_version(img["src"]) } images.to_a.map { |img| get_full_version(img["src"]) }
end end
@@ -74,7 +75,7 @@ module Sources
end end
def tags def tags
tags = page&.search(".info .tag, .main .tag a") tags = page&.search(".info .tag, .main .tag a, .tagarea")
tags.to_a.map do |tag| tags.to_a.map do |tag|
[tag.text, tag.attr("href")] [tag.text, tag.attr("href")]

View File

@@ -1,4 +1,4 @@
require 'test_helper' require "test_helper"
module Sources module Sources
class LofterTest < ActiveSupport::TestCase class LofterTest < ActiveSupport::TestCase
@@ -46,9 +46,13 @@ module Sources
context "A different CSS schema" do context "A different CSS schema" do
should "still find all the data" do should "still find all the data" do
source = Sources::Strategies.find("https://yuli031458.lofter.com/post/3163d871_1cbdc5f6d") source1 = Sources::Strategies.find("https://yuli031458.lofter.com/post/3163d871_1cbdc5f6d")
assert_equal(["https://imglf5.lf127.net/img/Mm55d3lNK2tJUWpNTjVLN0MvaTRDc1UvQUFLMGszOHRvSjV6S3VSa1lwa3BDWUtVOWpBTHBnPT0.jpg"], source.image_urls) source2 = Sources::Strategies.find("https://ssucrose.lofter.com/post/1d30f3e4_1cc58e9f0")
assert_not_empty(source.tags)
assert_equal(["https://imglf5.lf127.net/img/Mm55d3lNK2tJUWpNTjVLN0MvaTRDc1UvQUFLMGszOHRvSjV6S3VSa1lwa3BDWUtVOWpBTHBnPT0.jpg"], source1.image_urls)
assert_not_empty(source1.tags)
assert_equal(["https://imglf5.lf127.net/img/d052Q09DWkVNMVJwZm9rNURwNHdPcjlzRFlQc1BmTXArSG9TdXdJZnlCbUpEYnZJTHUwTGRRPT0.jpg"], source2.image_urls)
end end
end end