pdf script: format & add datetime (#4993)
This commit is contained in:

committed by
GitHub

parent
bd07d874ee
commit
5b5b590ee2
@@ -10,9 +10,11 @@ import glob
|
|||||||
import re
|
import re
|
||||||
import markdown
|
import markdown
|
||||||
import argparse
|
import argparse
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from weasyprint import HTML
|
from weasyprint import HTML
|
||||||
|
|
||||||
|
|
||||||
def main(loc, colorscheme):
|
def main(loc, colorscheme):
|
||||||
|
|
||||||
oslist = []
|
oslist = []
|
||||||
@@ -22,7 +24,7 @@ def main(loc, colorscheme):
|
|||||||
|
|
||||||
# Checking correctness of path
|
# Checking correctness of path
|
||||||
if not os.path.isdir(loc):
|
if not os.path.isdir(loc):
|
||||||
print("Invalid directory. Please try again!", file = sys.stderr)
|
print("Invalid directory. Please try again!", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Writing names of all directories inside 'pages' to a list
|
# Writing names of all directories inside 'pages' to a list
|
||||||
@@ -35,9 +37,13 @@ def main(loc, colorscheme):
|
|||||||
header = '<!doctype html><html><head><meta charset="utf-8"><link rel="stylesheet" href="basic.css">'
|
header = '<!doctype html><html><head><meta charset="utf-8"><link rel="stylesheet" href="basic.css">'
|
||||||
if colorscheme != "basic":
|
if colorscheme != "basic":
|
||||||
header += '<link rel="stylesheet" href="' + colorscheme + '.css"></head><body>\n'
|
header += '<link rel="stylesheet" href="' + colorscheme + '.css"></head><body>\n'
|
||||||
|
|
||||||
header += "</head><body>\n"
|
header += "</head><body>\n"
|
||||||
footer = "</body></html>"
|
footer = "</body></html>"
|
||||||
title_content = "<h1 class=title-main>tldr pages</h1><h4 class=title-sub>Simplified and community-driven man pages</h4></body></html>"
|
title_content = "<h1 class=title-main>tldr pages</h1>" \
|
||||||
|
+ "<h4 class=title-sub>Simplified and community-driven man pages</h4>" \
|
||||||
|
+ "<h6 class=title-sub><em><small>Generated on " + datetime.now().strftime("%c") + "</small></em></h6>" \
|
||||||
|
+ "</body></html>"
|
||||||
|
|
||||||
# Creating title page
|
# Creating title page
|
||||||
with open("title.html", "w") as f:
|
with open("title.html", "w") as f:
|
||||||
@@ -50,7 +56,8 @@ def main(loc, colorscheme):
|
|||||||
i = 1
|
i = 1
|
||||||
|
|
||||||
# Required string to create directory title pages
|
# Required string to create directory title pages
|
||||||
dir_title = "<h2 class=title-dir>" + operating_sys.capitalize() + "</h2></body></html>"
|
dir_title = "<h2 class=title-dir>" + \
|
||||||
|
operating_sys.capitalize() + "</h2></body></html>"
|
||||||
|
|
||||||
# Creating directory title page for current directory
|
# Creating directory title page for current directory
|
||||||
with open("dir_title.html", "w") as os_html:
|
with open("dir_title.html", "w") as os_html:
|
||||||
@@ -82,7 +89,8 @@ def main(loc, colorscheme):
|
|||||||
out.write(footer)
|
out.write(footer)
|
||||||
|
|
||||||
group.append(HTML("htmlout.html").render())
|
group.append(HTML("htmlout.html").render())
|
||||||
print("Rendered page {} of the directory {}".format(str(i), operating_sys))
|
print("Rendered page {} of the directory {}".format(
|
||||||
|
str(i), operating_sys))
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
allmd.clear()
|
allmd.clear()
|
||||||
@@ -114,8 +122,10 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Parsing the arguments
|
# Parsing the arguments
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("dir_path", help = "Path to the 'pages' directory")
|
parser.add_argument("dir_path", help="Path to the 'pages' directory")
|
||||||
parser.add_argument("-c", choices=["solarized-light", "solarized-dark"], help="Color scheme of the PDF")
|
parser.add_argument("-c",
|
||||||
|
choices=["solarized-light", "solarized-dark"],
|
||||||
|
help="Color scheme of the PDF")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
loc = args.dir_path
|
loc = args.dir_path
|
||||||
|
Reference in New Issue
Block a user