class SuttyMigration::WordpressXml::Post

Represents a WordPress post

Attributes

item[R]
wordpress[R]

Public Class Methods

new(wordpress:, item:) click to toggle source

@param :wordpress [SuttyMigration::WordpressXml] @param :item [Nokogiri::XML::Element]

   # File lib/sutty_migration/wordpress_xml/post.rb
14 def initialize(wordpress:, item:)
15   @wordpress = wordpress
16   @item = item
17 end

Public Instance Methods

attribute_value(key) click to toggle source

Get a value from the attribute

@return [String]

    # File lib/sutty_migration/wordpress_xml/post.rb
166 def attribute_value(key)
167   item.at_css(key).text
168 end
author() click to toggle source

Author attributes.

@return [Hash]

   # File lib/sutty_migration/wordpress_xml/post.rb
90 def author
91   @author ||= wordpress.authors[attribute_value('creator')]
92 end
categories() click to toggle source

Categories with attributes.

@return [Hash]

    # File lib/sutty_migration/wordpress_xml/post.rb
115 def categories
116   @categories ||= item.css('category').select do |c|
117     c[:domain] == 'category'
118   end.map do |c|
119     wordpress.categories[c[:nicename]]
120   end
121 end
content() click to toggle source

Content as HTML, with site URL removed.

@return [String]

   # File lib/sutty_migration/wordpress_xml/post.rb
81 def content
82   @content ||= WordpressFormatting::Wpautop.wpautop(attribute_value('encoded')).gsub(
83     / (href|src)="#{wordpress.url}/, ' \\1="'
84   )
85 end
date() click to toggle source

Publication date.

WordPress can store this date in three different fields and sometimes they come empty or invalid.

@return [Time]

   # File lib/sutty_migration/wordpress_xml/post.rb
64 def date
65   @date ||= %w[pubDate post_date_gmt post_date].map do |date_attr|
66     ::Jekyll::Utils.parse_date attribute_value(date_attr)
67   rescue StandardError
68   end.compact.first
69 end
description() click to toggle source

Description

@return [String]

   # File lib/sutty_migration/wordpress_xml/post.rb
47 def description
48   @description ||= attribute_value('description')
49 end
draft?() click to toggle source

Publication status

@return [Boolean]

    # File lib/sutty_migration/wordpress_xml/post.rb
159 def draft?
160   @draft ||= attribute_value('status') == 'draft'
161 end
id() click to toggle source

Post ID

@return [Integer]

   # File lib/sutty_migration/wordpress_xml/post.rb
26 def id
27   @id ||= attribute_value('post_id').to_i
28 end
inspect() click to toggle source
   # File lib/sutty_migration/wordpress_xml/post.rb
19 def inspect
20   "#<SuttyMigration::WordpressXml::Post title=\"#{title}\">"
21 end
last_modified_at() click to toggle source

Modification date.

@return [Time]

   # File lib/sutty_migration/wordpress_xml/post.rb
74 def last_modified_at
75   @last_modified_at ||= ::Jekyll::Utils.parse_date attribute_value('post_modified_gmt')
76 end
meta() click to toggle source

Metadata. Plugins store useful information here. Duplicated keys are returned as an Array of values.

@return [Hash]

    # File lib/sutty_migration/wordpress_xml/post.rb
127 def meta
128   @meta ||= {}.tap do |meta|
129     item.css('postmeta').each do |m|
130       key = m.css('meta_key').text
131       value = m.css('meta_value').text
132 
133       case meta[key]
134       when nil then meta[key] = value
135       when String then meta[key] = [meta[key], value]
136       when Array then meta[key] << value
137       end
138     end
139   end
140 end
order() click to toggle source

Order. Higher are sorted on top by jekyll-order.

@return [Integer]

    # File lib/sutty_migration/wordpress_xml/post.rb
145 def order
146   @order ||= attribute_value 'is_sticky'
147 end
password() click to toggle source

Post password. Use with jekyll-crypto.

@return [String]

   # File lib/sutty_migration/wordpress_xml/post.rb
97 def password
98   @password ||= attribute_value 'post_password'
99 end
published?() click to toggle source

Publication status

@return [Boolean]

    # File lib/sutty_migration/wordpress_xml/post.rb
152 def published?
153   @published ||= attribute_value('status') == 'publish'
154 end
slug() click to toggle source

Slug (“post name”)

@return [String]

   # File lib/sutty_migration/wordpress_xml/post.rb
54 def slug
55   @slug ||= attribute_value('post_name')
56 end
tags() click to toggle source

Tags with attributes.

@return [Hash]

    # File lib/sutty_migration/wordpress_xml/post.rb
104 def tags
105   @tags ||= item.css('category').select do |c|
106     c[:domain] == 'post_tag'
107   end.map do |c|
108     wordpress.tags[c[:nicename]]
109   end
110 end
title() click to toggle source

Title

@return [String]

   # File lib/sutty_migration/wordpress_xml/post.rb
40 def title
41   @title ||= attribute_value('title')
42 end