diff -urN v43/head.yaml v44/head.yaml --- v43/head.yaml 2019-10-15 17:21:09.000000000 +0900 +++ v44/head.yaml 2020-01-30 23:02:36.000000000 +0900 @@ -1,19 +1,6 @@ -head: -- '' -- '!--': ' Global site tag (gtag.js) - Google Analytics ' -- 'script async src="https://www.googletagmanager.com/gtag/js?id=UA-137368912-1"': '' -- script: - - '' - - " window.dataLayer = window.dataLayer || [];" - - " function gtag(){dataLayer.push(arguments);}" - - " gtag('js', new Date());" - - '' - - " gtag('config', 'UA-137368912-1');" - - '' -- '' - meta http-equiv="Content-Type" content="text/html;charset=iso-2022-jp": / -- title: untiled - style: 'pre{ background: lightgray; }' - style: 'img{ max-width: 100%; height: auto; }' - style: 'video{ max-width: 100%; height: auto; }' - style: 'h3{ border-left: solid gray; padding: 1em 0.5em; }' +# diff -urN v43/join_yaml.py v44/join_yaml.py --- v43/join_yaml.py 1970-01-01 09:00:00.000000000 +0900 +++ v44/join_yaml.py 2020-01-30 22:19:42.000000000 +0900 @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +import sys +import os +import arg +import dbg + +def out(s, spc=0, tail='\n'): + dbg.out(' ' * spc + s, tail) + +def out_to_k(f=sys.stdin, k=''): + while True: + s = f.readline() + if not s or s == k: + break + out(s, 2, '') + +if __name__ == "__main__": + # ./join_yaml.py [-t title] [-h head.yaml] + # cat head.yaml body.yaml | ./join_yaml.py [-t title] + + a = arg.new() + + out('html:') + out('- head:') + + title = a.pop_str('-t') + if title: + out('- title: ' + title, 2) + + f = sys.stdin + head = a.pop_str('-h') + if head: + paths = [ head, os.path.join( os.path.dirname(__file__), os.path.basename(head) ) ] + for path in paths: + if os.path.exists(path): + f = open(path, 'r') + if f: + break + if not f: + dbg.err_exit('not found header yaml file') + + out_to_k(f, '#\n') + + out('- body:') + out_to_k() +# EOF diff -urN v43/to_html.py v44/to_html.py --- v43/to_html.py 2020-01-24 11:42:20.000000000 +0900 +++ v44/to_html.py 2020-01-30 22:19:06.000000000 +0900 @@ -1,21 +1,27 @@ #!/usr/bin/env python import sys -import subprocess +import arg +import cmd_ut + +cmd_py = cmd_ut.cmd_py if __name__ == "__main__": - n = len(sys.argv) - if n < 3: - print( 'Usage: {} head.yaml body.txt [title]'.format( sys.argv[0] ) ) - sys.exit(1) - - title = sys.argv[3] if n > 3 else '' - - cmd_title = "sed 's/^- title: .*/- title: {}/'".format(title) if title else 'cat' - cmd_hd = 'cat {} | {} | ./ezhtml.py y'.format( sys.argv[1], cmd_title ) - - cmd = "( echo '' ; {} ; echo '' ; ./ezmd.py < {} | ./ezhtml.py y ; echo '' ) | nkf -j"; - cmd = cmd.format( cmd_hd, sys.argv[2] ) - #print(cmd) - subprocess.call(cmd, shell=True) + a = arg.new() + + title = a.pop_str('-t') + if title: + title = '-t ' + title + + head = a.pop_str('-h') + if head: + head = '-h ' + head + + out = a.pop_str('-o', 'index.html') + + body = a.pop('index.txt') + + fmt = '{} < {} | {} {} {} | {} y > {}' + cmd = fmt.format( cmd_py('ezmd'), body, cmd_py('join_yaml'), title, head, cmd_py('ezhtml'), out ) + cmd_ut.call(cmd) # EOF