Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joomla importer #188

Merged
merged 6 commits into from Nov 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/jekyll-import/importers/joomla.rb
Expand Up @@ -42,16 +42,25 @@ def self.process(options)
# Reads a MySQL database via Sequel and creates a post file for each
# post in wp_posts that has post_status = 'publish'. This restriction is
# made because 'draft' posts are not guaranteed to have valid dates.
query = "SELECT `title`, `alias`, CONCAT(`introtext`,`fulltext`) as content, `created`, `id` FROM #{table_prefix}content WHERE state = '0' OR state = '1' AND sectionid = '#{section}'"
query = "SELECT `title`, `alias`, CONCAT(`introtext`,`fulltext`) as content, `created`, `id` FROM #{table_prefix}content WHERE (state = '0' OR state = '1') AND sectionid = '#{section}'"

db[query].each do |post|
# Get required fields and construct Jekyll compatible name.
title = post[:title]
slug = post[:alias]
date = post[:created]
content = post[:content]
name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
slug]
id = post[:id]

# Construct a slug from the title if alias field empty.
# Remove illegal filename characters.
if !post[:alias] or post[:alias].empty?
slug = sluggify(post[:title])
else
slug = sluggify(post[:alias])
end

name = "%02d-%02d-%02d-%03d-%s.markdown" % [date.year, date.month, date.day,
id,slug]

# Get the relevant fields as a hash, delete empty fields and convert
# to YAML for the header.
Expand All @@ -71,6 +80,11 @@ def self.process(options)
end
end
end

# Borrowed from the Wordpress importer
def self.sluggify( title )
title = title.downcase.gsub(/[^0-9A-Za-z]+/, " ").strip.gsub(" ", "-")
end
end
end
end