From 29c7ad1ced1dfc271b4ab63474900b6bee342cfa Mon Sep 17 00:00:00 2001 From: gabe Date: Thu, 13 Jan 2022 15:54:00 -0600 Subject: [PATCH] User can now compile site with custom stylesheet. fixes #7 --- .gitignore | 3 +- ASCIIsite.py | 37 +- tests/control/css/asciidoctor.css | 15 +- tests/control/dir/subdir/linked.html | 2 +- tests/control/landing_page.html | 2 +- tests/control_css/css/test.css | 239 ++++++++++ tests/{result => control_css}/dir/collatz.py | 0 .../dir/subdir/linked.html | 5 +- .../images/test_pattern.svg | 0 .../{result => control_css}/landing_page.html | 5 +- tests/result/css/asciidoctor.css | 427 ------------------ tests/test.css | 239 ++++++++++ tests/test.sh | 15 + 13 files changed, 532 insertions(+), 457 deletions(-) create mode 100644 tests/control_css/css/test.css rename tests/{result => control_css}/dir/collatz.py (100%) rename tests/{result => control_css}/dir/subdir/linked.html (88%) rename tests/{result => control_css}/images/test_pattern.svg (100%) rename tests/{result => control_css}/landing_page.html (97%) delete mode 100644 tests/result/css/asciidoctor.css create mode 100644 tests/test.css diff --git a/.gitignore b/.gitignore index d793de9..cdf363a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ #test result -result/* +tests/result* +tests/result* #vim session files *.vims diff --git a/ASCIIsite.py b/ASCIIsite.py index 9860f1d..f0978b5 100755 --- a/ASCIIsite.py +++ b/ASCIIsite.py @@ -11,6 +11,7 @@ def parse_arguments(): parser=argparse.ArgumentParser(description='create a website directory structure by converting .adoc files in a directory strucutre to .html files.') parser.add_argument('inputDir', type=Path, help='The directory of adoc files to be copied and converted.') parser.add_argument('-o', '--output', type=Path, help='What to name the generated directory or tar file') + parser.add_argument('--stylesheet', type=Path, help='A custom CSS file to be applied to the output.') parser.add_argument('--exclude-file', type=Path, help='A text file containing glob patterns to exclude, 1 per line.') parser.add_argument('--exclude', nargs='+', help='A list of glob patterns to ignore. Remember to quote them so your shell doesnt escape them!') parser.add_argument('-z', '--compress', action='store_true', help='whether to compress the resulting directory to a tar.gz file. can be usefull for scripting to transfer the site to a remote server.') @@ -63,7 +64,12 @@ def parse_arguments(): print(f'Inputdir {args.inputDir.resolve()} does not exist!') exit() - return args.inputDir.resolve(), outFile, compress, exclude + stylesheet=None + if args.stylesheet != None: + stylesheet =args.stylesheet.resolve() + logging.info(f'using stylesheet {stylesheet}') + + return args.inputDir.resolve(), outFile, stylesheet, compress, exclude #Doing it in a tmpDir first, as some distrubutions put temp files on a ramdisk. this should speed up the operation sigificantly. class TmpDir: @@ -102,21 +108,18 @@ def find_relative_file_depth (subfile, parentDir): return len(subfile.parts)-len(parentDir.parts)-1 #simple wrapper around the asciidoctor cli. -def convert_file(inDir, outDir, inFile): +def convert_file(inDir: Path, outDir: Path, inFile: Path, stylesheet: Path): #in order for the stylesdir and imagesdir to be linked to correctly, we need to know the relative depth between the two directories. depth=find_relative_file_depth(inFile, inDir) logging.info(f'converting {Path(inFile).resolve()}') - logging.debug(f'converting {inFile} from directory {inDir} to directory {outDir} with a relative depth of {depth}') + logging.debug(f'converting {inFile=}, {outDir=}, {inDir=}, {stylesheet=}') depthstring= '../'*depth - try: - #the destdir can be used instead of destfile in order to preserve the directory structure relative to the base dir. really useful. - subprocess.run(['asciidoctor', + arguments=['asciidoctor', #makes the stylesheet linked, but still includes it in the output. '--attribute=linkcss', - '--attribute=copycss', f'--attribute=stylesdir={depthstring}css', #set imagesdir f'--attribute=imagesdir={depthstring}images', @@ -124,21 +127,29 @@ def convert_file(inDir, outDir, inFile): f'--source-dir={inDir}', #Destination dir. It takes the file from the subtree --source-dir and puts it in the equivilant location in the subtree --destination-dir. (talking about filesystem subtrees). f'--destination-dir={outDir}', - inFile], - check=True) + inFile] + + if stylesheet != None: + arguments.insert(1, f'--attribute=copycss={stylesheet}') + arguments.insert(1, f'--attribute=stylesheet={stylesheet.name}') + else: + arguments.insert(1, f'--attribute=copycss') + logging.debug(f'{arguments=}') + try: + #the destdir can be used instead of destfile in order to preserve the directory structure relative to the base dir. really useful. + subprocess.run(arguments, check=True) except Exception as e: logging.error(f'could not convert {inFile}!') - logging.error(f'stdErr was {e.stderr}') - logging.error(f'stdOut was {e.stdout}') + logging.error(f'{e}') if __name__ == '__main__': - inFile, outFile, compress, exclude=parse_arguments() + inFile, outFile, stylesheet, compress, exclude=parse_arguments() os.chdir(inFile) tmpDir=TmpDir('./', exclude) pathsToConvert=find_paths_to_convert('*.adoc') for i in pathsToConvert: - convert_file('./', tmpDir.path, i) + convert_file(inDir='./', outDir=tmpDir.path, inFile=i, stylesheet=stylesheet) if compress: tmpDir.compress_and_copy_self_to(outFile) diff --git a/tests/control/css/asciidoctor.css b/tests/control/css/asciidoctor.css index d6d02fb..98f27c4 100644 --- a/tests/control/css/asciidoctor.css +++ b/tests/control/css/asciidoctor.css @@ -183,7 +183,8 @@ body.toc2.toc-right{padding-left:0;padding-right:20em}} #content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221} details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em} details{margin-left:1.25rem} -details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;-webkit-tap-highlight-color:transparent} +details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent} +details>summary::-webkit-details-marker{display:none} details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)} details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)} details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem} @@ -225,9 +226,8 @@ pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none} table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none} table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal} table.linenotable td.code{padding-left:.75em} -table.linenotable td.linenos{border-right:1px solid;opacity:.35;padding-right:.5em} -pre.pygments .lineno{border-right:1px solid;opacity:.35;display:inline-block;margin-right:.75em} -pre.pygments .lineno::before{content:"";margin-right:-.125em} +table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} +pre.pygments span.linenos{display:inline-block;margin-right:.75em} .quoteblock{margin:0 1em 1.25em 1.5em;display:table} .quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em} .quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify} @@ -264,7 +264,7 @@ table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-c table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0} table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0} table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0} -table.stripes-all tr,table.stripes-odd tr:nth-of-type(odd),table.stripes-even tr:nth-of-type(even),table.stripes-hover tr:hover{background:#f8f8f7} +table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7} th.halign-left,td.halign-left{text-align:left} th.halign-right,td.halign-right{text-align:right} th.halign-center,td.halign-center{text-align:center} @@ -280,10 +280,11 @@ ol{margin-left:1.75em} ul li ol{margin-left:1.5em} dl dd{margin-left:1.125em} dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0} -ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em} +li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em} ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none} ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em} ul.unstyled,ol.unstyled{margin-left:0} +li>p:empty:only-child::before{content:"";display:inline-block} ul.checklist>li>p:first-child{margin-left:-1em} ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em} ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em} @@ -326,8 +327,6 @@ sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline} #footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em} #footnotes .footnote:last-of-type{margin-bottom:0} #content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0} -.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0} -.gist .file-data>table td.line-data{width:99%} div.unbreakable{page-break-inside:avoid} .big{font-size:larger} .small{font-size:smaller} diff --git a/tests/control/dir/subdir/linked.html b/tests/control/dir/subdir/linked.html index cf08c73..b15754c 100644 --- a/tests/control/dir/subdir/linked.html +++ b/tests/control/dir/subdir/linked.html @@ -4,7 +4,7 @@ - + relatively linked doc diff --git a/tests/control/landing_page.html b/tests/control/landing_page.html index 61aeb0c..99396e2 100644 --- a/tests/control/landing_page.html +++ b/tests/control/landing_page.html @@ -4,7 +4,7 @@ - + test page for an adoc static site generator. diff --git a/tests/control_css/css/test.css b/tests/control_css/css/test.css new file mode 100644 index 0000000..d071809 --- /dev/null +++ b/tests/control_css/css/test.css @@ -0,0 +1,239 @@ +/*template asciidoctor skin from https://github.com/darshandsoni/asciidoctor-skins/blob/gh-pages/css/template.css*/ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 Darshan Soni + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +/* document body (contains all content) */ +body { + font-size: small; +} + +/* document header (contains title etc) */ +#header { + width: 100%; +} + +/* headings */ +h1 { + color: purple; +} +h2 { + color: chartreuse; +} +h3 { + color: coral; +} +h4 { + color: darkcyan; +} +h5 { + color: darkslategray; +} +h6 { + color: olive; +} + +/* Table of Contents sidebar */ +#toc { + background-color: plum!important; + color: white; + font-weight: bold; +} +/* title of the TOC */ +#toctitle { + color: white; +} +/* top-level entries in TOC */ +.sectlevel1 { + background-color: palegoldenrod; +} +/* second-level entries in TOC */ +.sectlevel2 { + background-color: palegreen; +} + +/* main content window */ +#content { + background-color: lavender; + color: navy; +} + +/* plain paragraph text */ +.paragraph { + font-family: sans-serif; +} +p { + font-family: sans-serif; +} + +/* blockquote text */ +.quoteblock { + font-style: italic; +} +blockquote { + font-style: italic; +} + +/* the quotation mark itself (before the block) */ +.quoteblock blockquote::before { + color: blue; +} + +/* blockquote attribution text */ +.attribution { + font-size: x-large; +} + +/* blockquote citation (work where quote cited) */ +cite { + font-size: x-large; +} + +/* ordered list */ +ol { + color: red; +} +.olist { + color: red; +} + +/* unordered list */ +ul { + color: blue; +} +.ulist { + color: blue; +} + +/* links */ +a { + text-decoration: none; +} + +/* bold text */ +strong { + color: green; +} + +/* italic text */ +em { + color: orange; +} + +/* underlined text */ +u { + color: yellow; +} + +/* deleted text */ +del { + text-decoration: line-through; + color: red; +} +/* inserted text */ +ins { + text-decoration: overline; + color: green; +} + +/* strikethrough text */ +s { + text-decoration-color: red; +} + +/* superscript text */ +sup {} +/* subscript text */ +sub {} + +/* small text */ +small {} + +/* highlighted text */ +mark {} + +/* horizontal rules */ +hr {} + +/* table */ +table {} +/* table caption */ +caption {} +/* table header row */ +thead {} +/* table header cell */ +th {} +/* table row */ +tr {} +/* table footer */ +tfoot {} +/* table cell */ +td {} +/* table body */ +tbody {} + +/* inline code */ +code { + background-color: papayawhip!important; +} +/* pre-formatted text */ +pre { + background-color: burlywood!important; +} +.literalblock { + background-color: burlywood!important; +} + +/* image */ +img { + max-width: 100%; +} +/* image caption */ +.imageblock .title { + font-weight: bold!important; +} + +/* audio */ +audio {} +/* video */ +video {} + +/* footer section */ +#footer { + background-color: gray; + color: red; +} +/* footer text (by default contains time of last document update) */ +#footer-text { + font-weight: bold; + color: white; +} + +/* Responsiveness fixes */ +video { + max-width: 100%; +} + +@media all and (max-width: 600px) { +table { + width: 55vw!important; + font-size: 3vw; +} diff --git a/tests/result/dir/collatz.py b/tests/control_css/dir/collatz.py similarity index 100% rename from tests/result/dir/collatz.py rename to tests/control_css/dir/collatz.py diff --git a/tests/result/dir/subdir/linked.html b/tests/control_css/dir/subdir/linked.html similarity index 88% rename from tests/result/dir/subdir/linked.html rename to tests/control_css/dir/subdir/linked.html index cf08c73..5a1cf56 100644 --- a/tests/result/dir/subdir/linked.html +++ b/tests/control_css/dir/subdir/linked.html @@ -4,11 +4,10 @@ - + relatively linked doc - - +