summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormms <git@sapka.me>2024-12-05 00:02:53 +0100
committermms <git@sapka.me>2024-12-05 00:02:53 +0100
commita0320fa44b33d0080560b627bff6eb2b9ab1e30b (patch)
treed2acaaed2f20f212f28f8cdd6b37cf566b5c57eb /bin
parent662cdbda9f478c998859e3bb1ea3e63914032a29 (diff)
feat: add links with script
Diffstat (limited to 'bin')
-rwxr-xr-xbin/link.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/bin/link.rb b/bin/link.rb
new file mode 100755
index 0000000..4f23532
--- /dev/null
+++ b/bin/link.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require 'uri'
+require 'nokogiri'
+require 'open-uri'
+require 'openssl'
+require 'yaml'
+
+require "tty-prompt"
+
+prompt = TTY::Prompt.new
+
+Link = Struct.new(:url, :title, :date, :description, :button, :video)
+link = Link.new(date: Time.now.strftime('%Y-%m-%d'))
+
+link.url = prompt.ask("url:")
+
+title = URI.parse(link[:url]).open({ ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }) do |page|
+ noko = Nokogiri::HTML(page)
+ title = noko.xpath('//title').first.content
+ title = title.gsub("\n", " ")
+end
+
+link.title = prompt.ask("title:", value: title)
+link.description = prompt.ask("description:")
+link.button = prompt.ask("button:")
+link.video = prompt.ask("video site?:")
+
+# SAVE
+
+site_dir = File.expand_path('..', __dir__)
+data_path = "#{site_dir}/assets/more/links.yml"
+
+links = YAML.load_file(
+ data_path,
+ permitted_classes: [Date]
+)
+links['links'] << link.to_h.transform_keys(&:to_s)
+File.open(data_path, 'w') do |f|
+ f.write links.to_yaml
+end
+