pombola_extract_info_pages 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/pombola_extract_info_pages +62 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f89154a61ff407e6881aa03a37f7f229ee4dac7
|
4
|
+
data.tar.gz: dabf5fdeca23e6ca5de8479080a4cd4c10552524
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05a6c6c2f7684f8e54aea1ae755c7c636d9e2b12120d6a5dff471fec9a7a1ee1cb896a6195148edd4cee5fb897351a884199596ed56613929cce7dc3a23212f5
|
7
|
+
data.tar.gz: 77820583f3178164b4172551872195c5bd74d0b7e093d9dff9e333cb7543934393e681488d71d28c011dc7c0621e8896a8fae723e1e0c194f2f8a1bdaf7cb788
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'sequel'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
abort "Usage: DATABASE_URL=postgres://localhost/mzalendo-zw #$0" unless ENV['DATABASE_URL']
|
7
|
+
|
8
|
+
DB = Sequel.connect(ENV['DATABASE_URL'])
|
9
|
+
|
10
|
+
LINK_REGEX = /\[(?<text>.+?)\]\((?<url>.+?)(?: (?<title>".*?"))?\)/
|
11
|
+
|
12
|
+
def tidy_markdown(markdown)
|
13
|
+
markdown.tr!("\r\n", "\n")
|
14
|
+
markdown.gsub!(/\n+$/, "\n")
|
15
|
+
markdown.gsub!("\n\n**\n", "**\n")
|
16
|
+
markdown.strip!
|
17
|
+
links = markdown.to_enum(:scan, LINK_REGEX).map { Regexp.last_match }
|
18
|
+
return markdown unless links.any?
|
19
|
+
links.each do |link|
|
20
|
+
if link[:title] == '""'
|
21
|
+
# Get rid of empty title
|
22
|
+
markdown.sub!(link.to_s, "[#{link[:text].strip}](#{link[:url].strip})")
|
23
|
+
end
|
24
|
+
if !link[:url].lstrip.start_with?('/') && !link[:url].lstrip.start_with?('http')
|
25
|
+
# Fix relative links to be absolute
|
26
|
+
markdown.sub!(link.to_s, "[#{link[:text].strip}](/info/#{link[:url].strip})")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
markdown
|
30
|
+
end
|
31
|
+
|
32
|
+
def content_for(item, front_matter = {})
|
33
|
+
<<CONTENT
|
34
|
+
#{YAML.dump(front_matter)}---
|
35
|
+
|
36
|
+
#{tidy_markdown(item[:markdown_content])}
|
37
|
+
CONTENT
|
38
|
+
end
|
39
|
+
|
40
|
+
infopages_path = 'info'
|
41
|
+
FileUtils.mkdir_p(infopages_path)
|
42
|
+
|
43
|
+
DB[:info_infopage].where(kind: 'page').each do |page|
|
44
|
+
front_matter = {
|
45
|
+
'title' => page[:title].strip,
|
46
|
+
'slug' => page[:slug],
|
47
|
+
'permalink' => "/info/#{page[:slug]}/"
|
48
|
+
}
|
49
|
+
File.write(File.join(infopages_path, "#{page[:slug]}.md"), content_for(page, front_matter))
|
50
|
+
end
|
51
|
+
|
52
|
+
posts_path = '_posts'
|
53
|
+
FileUtils.mkdir_p(posts_path)
|
54
|
+
|
55
|
+
DB[:info_infopage].exclude(kind: 'page').each do |post|
|
56
|
+
front_matter = {
|
57
|
+
'title' => post[:title].strip,
|
58
|
+
'slug' => post[:slug],
|
59
|
+
'layout' => 'post'
|
60
|
+
}
|
61
|
+
File.write(File.join(posts_path, "#{post[:publication_date].to_date.to_s}-#{post[:slug]}.md"), content_for(post, front_matter))
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pombola_extract_info_pages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Mytton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sequel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.31'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.31'
|
27
|
+
description:
|
28
|
+
email: chrism@mysociety.org
|
29
|
+
executables:
|
30
|
+
- pombola_extract_info_pages
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/pombola_extract_info_pages
|
35
|
+
homepage: https://github.com/mysociety/pombola_extract_info_pages
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.5.1
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Extract infopages from a Pombola database dump
|
59
|
+
test_files: []
|
60
|
+
has_rdoc:
|