-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle.rb
More file actions
executable file
·83 lines (63 loc) · 1.79 KB
/
Copy pathsingle.rb
File metadata and controls
executable file
·83 lines (63 loc) · 1.79 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/local/bin/ruby
# = single.rb
#
# Author:: Dirk Meyer
# Copyright:: Copyright (c) 2020-2026 Dirk Meyer
# License:: Distributes under the same terms as Ruby
#
require 'yaml'
require 'fileutils'
$: << '.'
# wiki config file
CONFIG_FILE = 'wiki-config.yml'.freeze
# list of patterns with different color
# output index for pdf
SINGLE_PDF_INDEX = 'single.wiki'.freeze
# read wiki paths
def read_yaml( filename, default = {} )
config = default
return config unless File.exist?( filename )
config.merge!( YAML.load_file( filename ) )
end
# check if downloaded file has changed
def downloaded?( filename, buffer )
return false unless File.exist?( filename )
old = File.read( filename )
return true if buffer == old
false
end
# write buffer to file
def file_put_contents( filename, buffer, mode = 'w+' )
return if downloaded?( filename, buffer )
puts "Write: #{filename}"
File.open( filename, mode ) do |f|
f.write( buffer )
f.close
end
end
$config = read_yaml( CONFIG_FILE )
namespace = $config[ 'qspath' ].gsub( ':', '%3A' )
url = "https://#{$config[ 'host' ]}/doku.php?id=#{$config[ 'qspath' ]}&do=media&ns=#{namespace}"
wiki = "====== Single Scene Scripts as PDF ======
Get your script via the
[[#{url}||Media_Manager]]
"
@seen = {}
$config[ 'scenes' ].each do |scene|
next if scene == 'index'
@seen[ "single_#{scene}.html" ] = true
@seen[ "single_#{scene}.pdf" ] = true
@seen[ "single_#{scene}.wiki" ] = true
wiki << "Script for {{:#{$config[ 'qspath' ]}:single_#{scene}.pdf|#{scene}}}\\\\\n"
end
file_put_contents( SINGLE_PDF_INDEX, wiki )
Dir.glob( 'single_*' ).each do |filename|
case filename
when /[.]html$/, /[.]pdf$/, /[.]wiki$/
next if @seen[ filename ]
puts "removing old file: #{filename}"
File.unlink( filename )
end
end
exit 0
# eof