@@ -34,10 +34,12 @@ def data = NullData.new(title: nil, description: nil)
34
34
# def resource_data
35
35
delegate :data , to : :resource , allow_nil : true , prefix : true
36
36
37
- # We currently have a split system of Sitepress and Page models for handling static pages
38
- # While not ideal, it currently allows us to live in both worlds depending on the context.
39
- # Ultimately, migrating away from Sitepress for indexed content may be what‘s needed, but
40
- # keeping the split personality for now.
37
+ # We currently have a dual system of content management between Sitepress and
38
+ # Page models for handling static pages While not ideal, it currently allows
39
+ # us to live in both worlds depending on the context. Ultimately, migrating
40
+ # away from Sitepress for indexed content may be what‘s needed, but keeping
41
+ # the split personality for now.
42
+ #
41
43
def self . as_published_articles
42
44
SitepressArticle . take_published ( all . map { |page | SitepressArticle . new ( page . resource ) } )
43
45
end
@@ -63,20 +65,38 @@ def self.upsert_from_sitepress!(limit: nil)
63
65
enum . to_a
64
66
end
65
67
66
- def sitepress_article
67
- SitepressArticle . new ( resource )
68
+ def self . upsert_page_from_sitepress! ( sitepress_resource )
69
+ page = Page . find_or_initialize_by ( request_path : sitepress_resource . request_path )
70
+ page . published_at = sitepress_resource . data . published . to_time . middle_of_day if sitepress_resource . data . published
71
+ page . updated_at = sitepress_resource . data . updated . to_time . middle_of_day if sitepress_resource . data . updated
72
+ page . save!
73
+ page
68
74
end
69
75
76
+ def published? = !!published_at
77
+
78
+ def published_on = published_at &.to_date
79
+
80
+ def updated_on = updated_at &.to_date
81
+
82
+ def indexed? = !!indexed_at
83
+
84
+ def sitepress_article = SitepressArticle . new ( resource )
85
+
70
86
def resource = Sitepress . site . get ( request_path ) ||
71
87
NullResource . new ( request_path : request_path )
72
88
73
89
def body_text = Nokogiri ::HTML ( SitepressPage . render_html ( resource ) ) . text . squish
74
90
75
- def url = request_path
76
-
77
91
def title = resource . data . title
78
92
79
93
def body = resource . body
80
94
81
95
def description = resource . data . description
96
+
97
+ def meta_image = resource . data . meta_image
98
+
99
+ def toc = resource . data . toc
100
+
101
+ def enable_twitter_widgets = resource . data . toc
82
102
end
0 commit comments