Compare commits
3 commits
545ceef7c3
...
7458599ac2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7458599ac2 | ||
|
|
2a2a916ac1 | ||
|
|
2256adae26 |
2 changed files with 55 additions and 8 deletions
|
|
@ -57,19 +57,48 @@ class FicTracker::Cli::Story < Thor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'update STORY...', 'Force-update the listed stories'
|
||||||
|
def update(*stories)
|
||||||
|
setup!
|
||||||
|
|
||||||
|
stories.each do |story|
|
||||||
|
puts "Updating #{story} ..."
|
||||||
|
bend = FicTracker::Backends.find_backend story
|
||||||
|
if bend.nil?
|
||||||
|
puts " Can't update, no available backends."
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
bend = FicTracker::Backends.get(bend)
|
||||||
|
slug = story
|
||||||
|
slug = bend.parse_slug(story) if bend.respond_to? :parse_slug
|
||||||
|
|
||||||
|
story = FicTracker::Models::Story.find(backend_name: bend.name, slug:)
|
||||||
|
unless story
|
||||||
|
puts " Not tracking, skipping."
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
before = story.etag
|
||||||
|
story.refresh_metadata!
|
||||||
|
story.refresh_content!
|
||||||
|
render_story! story if story.etag != before
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc 'del STORY...', 'Remove stories from tracker'
|
desc 'del STORY...', 'Remove stories from tracker'
|
||||||
def del(*stories)
|
def del(*stories)
|
||||||
setup!
|
setup!
|
||||||
stories.each do |story|
|
stories.each do |story|
|
||||||
if story.include? '/'
|
if story.include? '/'
|
||||||
backend, slug = story.split '/'
|
backend_name, slug = story.split '/'
|
||||||
backend = nil if backend == '*'
|
backend_name = nil if backend_name == '*'
|
||||||
else
|
else
|
||||||
slug = story
|
slug = story
|
||||||
end
|
end
|
||||||
|
|
||||||
search = {
|
search = {
|
||||||
backend:,
|
backend_name:,
|
||||||
slug:
|
slug:
|
||||||
}.compact
|
}.compact
|
||||||
found = FicTracker::Models::Story.where(**search)
|
found = FicTracker::Models::Story.where(**search)
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,23 @@ module Kramdown::Converter
|
||||||
class SafeHtml < Base
|
class SafeHtml < Base
|
||||||
def initialize(root, options)
|
def initialize(root, options)
|
||||||
super
|
super
|
||||||
|
|
||||||
@options[:remove_block_html_tags] = true
|
@options[:remove_block_html_tags] = true
|
||||||
@options[:remove_span_html_tags] = false
|
@options[:remove_span_html_tags] = false
|
||||||
@options[:template] = 'string://<%= Html.convert(@body).first %>'
|
@options[:template] = 'string://<%= Html.convert(@body).first %>'
|
||||||
end
|
end
|
||||||
|
|
||||||
SUPERFLUOUS_TAGS = %w[align class justify]
|
ALLOWED_ATTRS = %w[alt dir hidden inert lang title translate]
|
||||||
|
|
||||||
def convert(el)
|
def convert(el)
|
||||||
real_el, el = el, el.value if el.type == :footnote
|
real_el, el = el, el.value if el.type == :footnote
|
||||||
|
|
||||||
# Strip out unnecessary HTML tags
|
# Strip out superfluous and invalid HTML 5 tags
|
||||||
SUPERFLUOUS_TAGS.each { |tag| el.attr.delete tag if el.attr.key? tag }
|
style = el.attr['style'] || ""
|
||||||
|
style += ";text-align:#{el.attr['align']}" if el.attr.key? 'align'
|
||||||
|
style = strip_style(style) if style.include? ':'
|
||||||
|
|
||||||
|
el.attr.delete_if { |key, _| !ALLOWED_ATTRS.include?(key) }
|
||||||
|
el.attr['style'] = style if style.include? ':'
|
||||||
|
|
||||||
children = el.children.dup
|
children = el.children.dup
|
||||||
index = 0
|
index = 0
|
||||||
|
|
@ -43,5 +47,19 @@ module Kramdown::Converter
|
||||||
|
|
||||||
real_el || el
|
real_el || el
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
ALLOWED_STYLE_ASSIGNMENTS = %w[font-size font-style font-weight text-align]
|
||||||
|
def strip_style(style)
|
||||||
|
parts = style.split(';').select { |p| p.include? ':' }.to_h do |assign|
|
||||||
|
parts = assign.split(':')
|
||||||
|
[parts.first.strip, parts.last.strip]
|
||||||
|
end
|
||||||
|
|
||||||
|
parts.delete_if { |key, _| !ALLOWED_STYLE_ASSIGNMENTS.include?(key) }
|
||||||
|
|
||||||
|
parts.map { |key, val| "#{key}:#{val}" }.join(';')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue