Skip to content

goooooouwa/blog_downloader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Read your favourite blog on your Kindle

Blog Downloader is a little ruby script that can turn your favourite blog into RSS feed. Combined with blog2kindle, you can turn any blog into an ebook to read on your ebook reader, such as Kindle, Apple Books.

Demo: ebook of the Coding Horror blog

Screen Shot 2021-11-25 at 6 48 48 PM

Screen Shot 2021-11-25 at 6 49 02 PM

Prerequesite

List of blog sites with built-in support

Example: turn Coding Horror blog into an ebook

1. Create page and post objects along with config.json

Coding Horror page and post object:

# blogs/coding_horror/coding_horror_page.rb
class CodingHorrorPage < Page
  def initialize(page_url, page_html)
    super(page_url, page_html)
    next_page_url_node = page_html.css(".left .read-next-title a").first
    previous_page_url_node = page_html.css(".right .read-next-title a").first
    @next_page_url = "https://blog.codinghorror.com#{ next_page_url_node.attributes["href"].value }" unless next_page_url_node.nil?
    @previous_page_url = "https://blog.codinghorror.com#{ previous_page_url_node.attributes["href"].value }" unless previous_page_url_node.nil?
    @post_urls = [@page_url]
  end
end

# blogs/coding_horror/coding_horror_posts.rb
class CodingHorrorPost < Post
  def initialize(post_url, post_html)
    super(post_url, post_html)
    @title = post_html.css(".post-title").text
    @published_date = post_html.at("meta[property='article:published_time']")['content']
    @content = post_html.css(".post-content").children
    @author = "Jeff Atwood"
  end
end

Config file:

// blogs/coding_horror/config.json
{
    "title": "Coding Horror",
    "description": "programming and human factors",
    "homepage": "https://blog.codinghorror.com",
    "direction": "previous",
    "remote_base_url": "https://raw.githubusercontent.com/goooooouwa/out/master/coding_horror",
    "initial_page": "https://blog.codinghorror.com/building-a-pc-part-ix-downsizing/"
}

2. Fetch all pages of the Coding Horror blog

ruby ./bin/run.rb page coding_horror

3. Fetch all posts of the Coding Horror blog

ruby ./bin/run.rb post coding_horror

4. Generate the RSS feed

ruby ./bin/run.rb render coding_horror   # generate RSS file in config["our_dir"]

5. Publish the RSS feed

For example, you can publish the RSS feed to a Github repo:

git add ./out/rss.xml
git commit -m "publish blog feeds"
git push origin master   # publish the RSS file somewhere online to get an public link

6. generate the ebook

# in blog2kindle
echo "https://raw.githubusercontent.com/goooooouwa/out/master/out/rss.xml" > config/feeds.txt
python3 src/news2kindle.py

Now you will have your favourite blog sent to your Kindle, waiting for you to pick up.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages