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
|
||||
|
||||
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'
|
||||
def del(*stories)
|
||||
setup!
|
||||
stories.each do |story|
|
||||
if story.include? '/'
|
||||
backend, slug = story.split '/'
|
||||
backend = nil if backend == '*'
|
||||
backend_name, slug = story.split '/'
|
||||
backend_name = nil if backend_name == '*'
|
||||
else
|
||||
slug = story
|
||||
end
|
||||
|
||||
search = {
|
||||
backend:,
|
||||
backend_name:,
|
||||
slug:
|
||||
}.compact
|
||||
found = FicTracker::Models::Story.where(**search)
|
||||
|
|
|
|||
|
|
@ -14,13 +14,17 @@ module Kramdown::Converter
|
|||
@options[:template] = 'string://<%= Html.convert(@body).first %>'
|
||||
end
|
||||
|
||||
SUPERFLUOUS_TAGS = %w[align class justify]
|
||||
|
||||
ALLOWED_ATTRS = %w[alt dir hidden inert lang title translate]
|
||||
def convert(el)
|
||||
real_el, el = el, el.value if el.type == :footnote
|
||||
|
||||
# Strip out unnecessary HTML tags
|
||||
SUPERFLUOUS_TAGS.each { |tag| el.attr.delete tag if el.attr.key? tag }
|
||||
# Strip out superfluous and invalid HTML 5 tags
|
||||
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
|
||||
index = 0
|
||||
|
|
@ -43,5 +47,19 @@ module Kramdown::Converter
|
|||
|
||||
real_el || el
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue