-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRakefile
More file actions
66 lines (57 loc) · 1.61 KB
/
Copy pathRakefile
File metadata and controls
66 lines (57 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require "dotenv"
Dotenv.load
require "octokit"
task default: :download_release_notes
desc "Downloads latest release notes and creates news posts"
task :download_release_notes do
client = Octokit::Client.new(access_token: ENV.fetch("GITHUB_ACCESS_TOKEN"))
releases = client.releases("manyfold3d/manyfold")
create_latest_release_file(releases.first)
releases.each do |release|
create_release_notes_file(release)
end
end
def create_latest_release_file(release)
File.open("_data/releases.yml", "w") do |f|
f.puts <<~EOF
---
latest:
name: #{release.name}
path: #{permalink(release)}
EOF
end
end
def create_release_notes_file(release)
File.open("_posts/#{filename(release)}.md", "w") do |f|
f.puts <<~EOF
---
title: Release #{release.name}
date: #{release.published_at}
category: releases
---
#{fix_links release.body}
See the original release on GitHub: [#{release.name}](#{release.html_url})
EOF
end
end
def filename(release)
[
release.published_at.strftime("%F"),
"release",
release.name.tr(".", "-")
].join("-")
end
def permalink(release)
[
"",
"news",
release.published_at.strftime("%Y/%m/%d"),
"release-#{release.name.tr(".", "-")}.html"
].join("/")
end
def fix_links(markdown)
markdown.gsub!(/https:\/\/github.com\/([\w\/]+)\/pull\/([0-9]+)/, "[#\\2](https://github.com/\\1/pull/\\2)")
markdown.gsub!(/(\s)@(\w+)(\s)/, "\\1[@\\2](https://github.com/\\2)\\3")
markdown.gsub!(/https:\/\/github.com\/([\w\/]+)\/compare\/([\w.]+)/, "[\\2](https://github.com/\\1/compare/\\2)")
markdown
end