al_ext_posts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +6 -0
  3. data/LICENSE +20 -0
  4. data/README.md +60 -0
  5. data/lib/al_ext_posts.rb +124 -0
  6. metadata +165 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8837eae98b908633289d5d3461572abe7d662d1ff4424663d025ee17ab4ddacb
4
+ data.tar.gz: af0dac1c1621c4338710a06abbbd0420bb120ddf69b58bde51705c333af199b2
5
+ SHA512:
6
+ metadata.gz: 762ec2aebbf96538c899df02bf97baa4b5751848cfcde4eab8f659e88597ccffe0fc8bb5d42e086f27c141d887a551e7c940b6242fdad4e39597a9a8e286677e
7
+ data.tar.gz: e88c4b4e4894455d584ab285962e53cdd5d98892498b4a526bfd66760d05100c2354058e89c289e418d0ef07e40cf7a66cc1b879f1efee9adc68dd9f750c0758
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-02-07
4
+ - Initial gem release.
5
+ - Added external post import from RSS feeds and explicit URL lists.
6
+ - Added RSS parse error handling and per-source default categories/tags.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Maruan Al-Shedivat.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Al-Ext-Posts
2
+
3
+ A Jekyll plugin that allows you to fetch and display external blog posts from RSS feeds and specific URLs in your Jekyll site.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Jekyll site's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'al_ext_posts'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ 1. Add the plugin to your site's `_config.yml`:
22
+
23
+ ```yaml
24
+ plugins:
25
+ - al_ext_posts
26
+ ```
27
+
28
+ 2. Configure your external sources in `_config.yml`:
29
+
30
+ ```yaml
31
+ external_sources:
32
+ - name: "My Blog"
33
+ rss_url: "https://myblog.com/feed.xml"
34
+ categories: ["external", "blog"]
35
+ tags: ["rss", "updates"]
36
+ - name: "Another Source"
37
+ categories: ["external"]
38
+ tags: ["manual-curation"]
39
+ posts:
40
+ - url: "https://example.com/post1"
41
+ published_date: "2024-03-20"
42
+ - url: "https://example.com/post2"
43
+ published_date: "2024-03-21"
44
+ ```
45
+
46
+ The plugin supports two types of sources:
47
+ - RSS feeds: Provide the `rss_url` parameter
48
+ - Direct URLs: Provide a list of `posts` with `url` and `published_date`
49
+
50
+ Optional per-source defaults:
51
+ - `categories`: array of categories automatically applied to imported posts
52
+ - `tags`: array of tags automatically applied to imported posts
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bundle install` to install dependencies.
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub.
@@ -0,0 +1,124 @@
1
+ require 'feedjira'
2
+ require 'httparty'
3
+ require 'jekyll'
4
+ require 'nokogiri'
5
+ require 'time'
6
+
7
+ module AlExtPosts
8
+ class ExternalPostsGenerator < Jekyll::Generator
9
+ safe true
10
+ priority :high
11
+
12
+ def generate(site)
13
+ if site.config['external_sources'] != nil
14
+ site.config['external_sources'].each do |src|
15
+ puts "Fetching external posts from #{src['name']}:"
16
+ if src['rss_url']
17
+ fetch_from_rss(site, src)
18
+ elsif src['posts']
19
+ fetch_from_urls(site, src)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def fetch_from_rss(site, src)
26
+ xml = HTTParty.get(src['rss_url']).body
27
+ return if xml.nil?
28
+ begin
29
+ feed = Feedjira.parse(xml)
30
+ rescue StandardError => e
31
+ puts "Error parsing RSS feed from #{src['rss_url']} - #{e.message}"
32
+ return
33
+ end
34
+ process_entries(site, src, feed.entries)
35
+ end
36
+
37
+ def process_entries(site, src, entries)
38
+ entries.each do |e|
39
+ puts "...fetching #{e.url}"
40
+ create_document(site, src['name'], e.url, {
41
+ title: e.title,
42
+ content: e.content,
43
+ summary: e.summary,
44
+ published: e.published
45
+ }, src)
46
+ end
47
+ end
48
+
49
+ def create_document(site, source_name, url, content, src = {})
50
+ # check if title is composed only of whitespace or foreign characters
51
+ if content[:title].gsub(/[^\w]/, '').strip.empty?
52
+ # use the source name and last url segment as fallback
53
+ slug = "#{source_name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')}-#{url.split('/').last}"
54
+ else
55
+ # parse title from the post or use the source name and last url segment as fallback
56
+ slug = content[:title].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
57
+ slug = "#{source_name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')}-#{url.split('/').last}" if slug.empty?
58
+ end
59
+
60
+ path = site.in_source_dir("_posts/#{slug}.md")
61
+ doc = Jekyll::Document.new(
62
+ path, { :site => site, :collection => site.collections['posts'] }
63
+ )
64
+ doc.data['external_source'] = source_name
65
+ doc.data['title'] = content[:title]
66
+ doc.data['feed_content'] = content[:content]
67
+ doc.data['description'] = content[:summary]
68
+ doc.data['date'] = content[:published]
69
+ doc.data['redirect'] = url
70
+
71
+ # Apply default categories and tags from source configuration
72
+ if src['categories'] && src['categories'].is_a?(Array) && !src['categories'].empty?
73
+ doc.data['categories'] = src['categories']
74
+ end
75
+ if src['tags'] && src['tags'].is_a?(Array) && !src['tags'].empty?
76
+ doc.data['tags'] = src['tags']
77
+ end
78
+
79
+ doc.content = content[:content]
80
+ site.collections['posts'].docs << doc
81
+ end
82
+
83
+ def fetch_from_urls(site, src)
84
+ src['posts'].each do |post|
85
+ puts "...fetching #{post['url']}"
86
+ content = fetch_content_from_url(post['url'])
87
+ content[:published] = parse_published_date(post['published_date'])
88
+ create_document(site, src['name'], post['url'], content, src)
89
+ end
90
+ end
91
+
92
+ def parse_published_date(published_date)
93
+ case published_date
94
+ when String
95
+ Time.parse(published_date).utc
96
+ when Date
97
+ published_date.to_time.utc
98
+ else
99
+ raise "Invalid date format for #{published_date}"
100
+ end
101
+ end
102
+
103
+ def fetch_content_from_url(url)
104
+ html = HTTParty.get(url).body
105
+ parsed_html = Nokogiri::HTML(html)
106
+
107
+ title = parsed_html.at('head title')&.text.strip || ''
108
+
109
+ description = parsed_html.at('head meta[name="description"]')&.attr('content')
110
+ description ||= parsed_html.at('head meta[name="og:description"]')&.attr('content')
111
+ description ||= parsed_html.at('head meta[property="og:description"]')&.attr('content')
112
+
113
+ body_content = parsed_html.search('p').map { |e| e.text }
114
+ body_content = body_content.join() || ''
115
+
116
+ {
117
+ title: title,
118
+ content: body_content,
119
+ summary: description
120
+ # Note: The published date is now added in the fetch_from_urls method.
121
+ }
122
+ end
123
+ end
124
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: al_ext_posts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - al-org
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: feedjira
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3.2'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: httparty
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0.18'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0.18'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '1.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: nokogiri
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '1.13'
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '1.13'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '2.0'
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '2.0'
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '2.0'
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '3.0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '13.0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '13.0'
127
+ description: Jekyll plugin extracted from al-folio that imports external posts from
128
+ RSS feeds or explicit URLs, with support for default tags and categories per source.
129
+ email:
130
+ - dev@al-org.dev
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - CHANGELOG.md
136
+ - LICENSE
137
+ - README.md
138
+ - lib/al_ext_posts.rb
139
+ homepage: https://github.com/al-org-dev/al-ext-posts
140
+ licenses:
141
+ - MIT
142
+ metadata:
143
+ allowed_push_host: https://rubygems.org
144
+ homepage_uri: https://github.com/al-org-dev/al-ext-posts
145
+ source_code_uri: https://github.com/al-org-dev/al-ext-posts
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '2.7'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.0.3.1
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Import external posts from RSS feeds and URLs
165
+ test_files: []