Compare commits

..

No commits in common. "7154eed2f9362655a6952a18ae399e7be05a888c" and "254bf1f9e65e4f58550c0313acb4231666d39a6e" have entirely different histories.

4 changed files with 23 additions and 159 deletions

View file

@ -1,27 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Liest markdownfile ein und spuckt html aus: md2html meinmarkdownfile.md
"""
import sys, markdown2 as markdown
markdown.Markdown.extras = ["break-on-newline", "footnotes"]
try:
mdfile = sys.argv[1]
except:
sys.exit("No file, honey.\n"+sys.argv[0]+ ": Liest markdownfile ein und spuckt html aus: md2html meinmarkdownfile.md")
headline = mdfile.split(".md")[0]
htmlfilename = headline + ".html"
myhead = "<!DOCTYPE HTML><html><head><title>" + headline + "</title></head><body>"
myfooter = "</body></html>"
with open(mdfile, "r", encoding="utf-8") as datafile:
md = datafile.read()
htmlcontent = markdown.markdown(md, extras=markdown.Markdown.extras)
with open(htmlfilename, "w", encoding="utf-8") as outfile:
outfile.write(myhead + htmlcontent + myfooter)

View file

@ -1,70 +0,0 @@
#!/usr/bin/env python3
import sys, os, re, datetime, locale
webbasedir = os.path.expanduser("~/Media")
### for module mkdirindex:
targetdir = webbasedir + "/Videos"
indexfilename = "index.html"
targetdirheadline = "Something."
showsize = 0
####
def mkdirindex(targetdir, indexfilename, targetdirheadline, showsize):
"""Dig a directory and generate an index."""
head1 = (
'<!DOCTYPE HTML><html><head>\n <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n<title>'
+ targetdirheadline
+ '</title>\n <meta name="syntax" content="markdown">\n <meta name="generator" content="'
+ "webgen.py"
+ ' markdown2htmlconverter">\n <meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">'
)
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
head2 = "</head><body>"
body1 = '<a class="Statement" href="../">Main</a><br/><br/>'
body1 += '<div class="Statement">' + targetdirheadline + "</div> "
body1 += '<table border="0" class="Neutral">'
foot = '</table><br/><strong>Some byebye</strong><br/><hr class="myhr" ></body> </html>\n'
linecounter = 0
dirindexfile = open(targetdir + indexfilename, "w")
dirindexfile.write(head1 + style_fn + head2 + body1)
sortedtargetdir = os.listdir(targetdir)
sortedtargetdir.sort()
sortedtargetdir.reverse()
for file in sortedtargetdir:
sizestr = ""
# If showsize is 1 we have some filesdir and want to see the size of a file
if not re.match("^\.", file) and not file == indexfilename:
if showsize == 1:
size = os.lstat(targetdir + file).st_size
if size > 100000000000:
sizestr = str(int(size / 1073741824)) + " GiB"
elif size > 100000000:
sizestr = str(int(size / 1048576)) + " MiB"
elif size > 10000:
sizestr = str(int(size / 1024)) + " KiB"
else:
sizestr = str(size) + " B"
else:
entryname = re.sub(".html$", "", file)
# entryname = re.sub(".html$", "", re.sub("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] ", "", file))
line = str('<tr><td><a href="' + str(file) + '">' + entryname + "</a></td><td>&nbsp;" + sizestr + "</td></tr>")
dirindexfile.write(line)
linecounter += 1
dirindexfile.write(foot)
return linecounter
# Dig the files-directory and generate an index.
linecounter = mkdirindex(targetdir, indexfilename, targetdirheadline, showsize)
print("Dirindex in ", targetdir, " has ", linecounter, "lines")
# Have a nice time.

View file

@ -1,38 +1,20 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys, os, uuid, shutil, signal, subprocess, markdown2 as markdown, re, datetime, locale, glob import sys, os, uuid, shutil, signal, subprocess, markdown, re, datetime, locale, glob
from dialog import Dialog from dialog import Dialog
# If not choosen stdout as output, where should the generated file go to and what # If not choosen stdout as output, where should the generated file go to and what
# fileending (f.e. .html) shall it have. Preset values. # fileending (f.e. .html) shall it have
webbasedir = os.path.expanduser("~/www/i21k.de/") webbasedir = os.path.expanduser("~/www/i21k.de/")
targetdir = webbasedir + "posts/" targetdir = webbasedir + "posts/"
sourcedir = os.path.expanduser("~/python/webgen/mds/") sourcedir = os.path.expanduser("~/python/webgen/")
### for module mkdirindex: ### for module mkdirindex:
filesdir = webbasedir + "files/" filesdir = webbasedir + "files/"
indexfilename = "index.html" indexfilename = "index.html"
filesdirheadline = "Files" filesdirheadline = "Files"
#### ####
# for spellchecko
# Preferred: aspell -c filename
#
dospellcheck = os.getenv("SPELLCHECK")
spellcheck = "aspell"
spellcheckparam = "-c"
# Configure Markdown, activate "break-on-newline" for letting a line end without havin to put doublespaces there.
#
# More options:
# break-on-newline, code-friendly, cuddled-lists, fenced-code-blocks,
# footnotes, header-ids, highlightjs-lang, html-classes, link-patterns,
# markdown-in-html, numbering, pyshell, smarty-pants, spoiler, strike,
# tag-friendly, tables, toc, use-file-vars, wiki-tables, xml
markdown.Markdown.extras = ["footnotes", "break-on-newline"]
fileending = "" fileending = ""
locale.setlocale(locale.LC_ALL, "") locale.setlocale(locale.LC_ALL, "")
clear = "\x1b[2J\x1b[H" clear = "\x1b[2J\x1b[H"
@ -65,19 +47,11 @@ signal.signal(signal.SIGINT, sigint_handler)
# call favorite editor with filename to write the text # call favorite editor with filename to write the text
# i am not shure bout that spellchecko, is it nessesary?
def edit(headline): def edit(headline):
editor = os.getenv("EDITOR") editor = os.getenv("EDITOR")
if not editor: if not editor:
editor = "vim" editor = "vim"
subprocess.call([editor, headline]) subprocess.call([editor, headline])
if dospellcheck:
print(yellow)
if input("You like to spellcheck it first [y/N]?") == "y":
subprocess.call([spellcheck, spellcheckparam, headline])
print(green)
return headline return headline
@ -106,7 +80,7 @@ def selectfile():
# Nothing has been choosen, so lets ask for a topic to generate a filename # Nothing has been choosen, so lets ask for a topic to generate a filename
if ausgewaehlt[0] == "cancel": if ausgewaehlt[0] == "cancel":
newtopic = d.inputbox("Ok, gib hier ein neues Thema an:", width=xwidth, height=ywidth, title="Ein Thema wählen:", cancel="Exit") # newtopic = d.inputbox("Ok, gib hier ein neues Thema an:", width=xwidth, height=ywidth, title="Ein Thema wählen:", cancel="Exit")
if newtopic[0] == "cancel" or newtopic[1] == "": if newtopic[0] == "cancel" or newtopic[1] == "":
sys.exit(yellow + "Na, dann eben nicht...") sys.exit(yellow + "Na, dann eben nicht...")
headline = newtopic[1] headline = newtopic[1]
@ -136,7 +110,6 @@ def selectfile():
return sourcefile, targetfile, headline return sourcefile, targetfile, headline
def mkdirindex(filesdir, indexfilename, filesdirheadline): def mkdirindex(filesdir, indexfilename, filesdirheadline):
"""Dig the files-directory and generate an index.""" """Dig the files-directory and generate an index."""
@ -149,11 +122,11 @@ def mkdirindex(filesdir, indexfilename, filesdirheadline):
) )
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">' style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
head2 = "</head><body><div id=\'print\'><img src=\"/copyright.jpg\" /></div>\n" head2 = "</head><body>"
body1 = '<a class="Statement" href="../">Back</a><br/><br/><hr>' body1 = '<a class="Statement" href="../">Back</a><br/><br/><hr>'
body1 += '<div class="Statement"> Some files. Maybe useful or not.</div> ' body1 += '<div class="Statement"> Some files. Maybe useful or not.</div> '
body1 += '<table border="0" class="Neutral">' body1 += '<table border="0" class="Neutral">'
foot = '</table><br/><strong>You can\'t avoid chaos.</strong><br/><hr class="myhr" ></body> </html>\n' foot = "</table><br/><strong>You can't avoid chaos.</strong><br/><hr></body> </html>\n"
linecounter=0 linecounter=0
dirindexfile = open(filesdir + indexfilename, "w") dirindexfile = open(filesdir + indexfilename, "w")
@ -180,13 +153,14 @@ def mkdirindex(filesdir, indexfilename, filesdirheadline):
return linecounter return linecounter
# Parse arguments "--html", "--stdout", --spellcheck and "Some Headline"
# Parse arguments "--html", "--stdout" and "Some Headline"
# there are 3 parameters. if --html is given, the fileending will be .html. # there are 3 parameters. if --html is given, the fileending will be .html.
# Else, if stdout is choosen there can be no fileending, but it will still contain html # Else, if stdout is choosen there can be no fileending, but it will still contain html
# the name of the program is stored in myname # the name of the program is stored in myname
# dont set a name to outfile, it just is initialised here and will be overwritten # dont set a name to outfile, it just is initialised here and will be overwritten
optwords = ["--html", "--stdout", "--spellcheck"] optwords = ["--html", "--stdout"]
outfile = "" outfile = ""
args = sys.argv args = sys.argv
myname = args.pop(0) myname = args.pop(0)
@ -195,9 +169,6 @@ for wish in optwords:
if wish == "--html": if wish == "--html":
fileending = ".html" fileending = ".html"
args.pop(args.index(wish)) args.pop(args.index(wish))
if wish == "--spellcheck":
dospellcheck = "y"
args.pop(args.index(wish))
if wish == "--stdout": if wish == "--stdout":
outfile = sys.stdout outfile = sys.stdout
args.pop(args.index(wish)) args.pop(args.index(wish))
@ -257,11 +228,11 @@ head1 = (
# Some fancy css for minimalistic terminal style # Some fancy css for minimalistic terminal style
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">' style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
head2 = "</head><body>\n<div id=\'print\'><img src=\"/copyright.jpg\" /></div>\n" head2 = "</head><body>\n"
body1 = '<a href="./">Back</a><blockquote><strong>Moin</strong></p>' body1 = '<a href="./">Back</a><blockquote><strong>Moin</strong></p>'
foot = '<br /><hr class="myhr" />\n</body> </html>\n' foot = "<br /><blockquote><blockquote><blockquote><blockquote><blockquote><blockquote></p><hr /></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></body> </html>\n"
foot = "<br /><hr width=50% /></body> </html>\n"
# write beginning of html-file # write beginning of html-file
html_out_file.write(head1 + style_fn + head2 + body1) html_out_file.write(head1 + style_fn + head2 + body1)

View file

@ -23,16 +23,6 @@ dospellcheck = os.getenv("SPELLCHECK")
spellcheck = "aspell" spellcheck = "aspell"
spellcheckparam = "-c" spellcheckparam = "-c"
# Configure Markdown, activate "break-on-newline" for letting a line end without havin to put doublespaces there.
#
# More options:
# break-on-newline, code-friendly, cuddled-lists, fenced-code-blocks,
# footnotes, header-ids, highlightjs-lang, html-classes, link-patterns,
# markdown-in-html, numbering, pyshell, smarty-pants, spoiler, strike,
# tag-friendly, tables, toc, use-file-vars, wiki-tables, xml
markdown.Markdown.extras = ["footnotes", "break-on-newline"]
fileending = "" fileending = ""
locale.setlocale(locale.LC_ALL, "") locale.setlocale(locale.LC_ALL, "")
clear = "\x1b[2J\x1b[H" clear = "\x1b[2J\x1b[H"
@ -149,11 +139,11 @@ def mkdirindex(filesdir, indexfilename, filesdirheadline):
) )
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">' style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
head2 = "</head><body><div id='print'><img src=\"/copyright.jpg\" />XXXXXXXX</div>\n" head2 = "</head><body>"
body1 = '<a class="Statement" href="../">Back</a><br/><br/><hr>' body1 = '<a class="Statement" href="../">Back</a><br/><br/><hr>'
body1 += '<div class="Statement"> Some files. Maybe useful or not.</div> ' body1 += '<div class="Statement"> Some files. Maybe useful or not.</div> '
body1 += '<table border="0" class="Neutral">' body1 += '<table border="0" class="Neutral">'
foot = '</table><br/><strong>You can\'t avoid chaos.</strong><br/><hr class="myhr" ></body> </html>\n' foot = "</table><br/><strong>You can't avoid chaos.</strong><br/><hr></body> </html>\n"
linecounter = 0 linecounter = 0
dirindexfile = open(filesdir + indexfilename, "w") dirindexfile = open(filesdir + indexfilename, "w")
@ -259,9 +249,9 @@ head1 = (
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">' style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
head2 = "</head><body>\n<div id='print'><img src=\"/copyright.jpg\" />XXXXXXXX</div>\n" head2 = "</head><body>\n"
body1 = '<a href="./">Back</a><blockquote><strong>Moin</strong></p>' body1 = '<a href="./">Back</a><blockquote><strong>Moin</strong></p>'
foot = '<br /><hr class="myhr" />\n</body> </html>\n' foot = "<br /><hr width=50% /></body> </html>\n"
# write beginning of html-file # write beginning of html-file
html_out_file.write(head1 + style_fn + head2 + body1) html_out_file.write(head1 + style_fn + head2 + body1)