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
|
# File 'lib/pinboard_logseq/cli.rb', line 21
def execute
data = JSON.parse(File.read(IMPORT_FILE))
pins = data.map { |json| Pin.from_hash(json) }
pins_by_year_and_month = pins.group_by { |p| [p.time.year, p.time.month] }
pins_by_year_and_month.each do |(year, month), pins|
content = ""
pins.each do |pin|
year = pin.time.strftime("%Y")
month_name_short = pin.time.strftime("%b")
day = pin.time.day.ordinalize
formatted_date = "#{month_name_short} #{day}, #{year}"
content +=
"- 🔖 [#{pin.description || "No description"}](#{pin.href}) [[#{formatted_date}]] "
content += "\n> #{pin.extended}" if pin.extended && pin.extended != "" && pin.extended != "undefined"
tag_bits = pin.tags.map { |t| "[[#{t}]]" }
tag_bits << "[[Pinboard - To Read]]" if pin.to_read
content += tag_bits.join(" ")
content += "\n"
end
month_name_long = pins.first.time.strftime("%B")
File.write(
"output/Pinboard Import ___ #{year} ___ #{month_name_long}.md",
content
)
end
end
|