diff --git a/ASCIIsite.py b/ASCIIsite.py index cd825c0..8d5b212 100755 --- a/ASCIIsite.py +++ b/ASCIIsite.py @@ -12,6 +12,7 @@ def parse_arguments(): 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('-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.') + parser.add_argument('--exclude', nargs='+', help='A list of glob patterns to ignore. Remember to quote them so your shell doesnt escape them!') args=parser.parse_args() #set compress flag @@ -43,15 +44,17 @@ def parse_arguments(): logging.info(f'outputting to {outFile.resolve()}') logging.debug(f'compress is {compress}') - return args.inputDir.resolve(), outFile, compress + return args.inputDir.resolve(), outFile, compress, args.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: - def __init__(self, srcDir): + def __init__(self, srcDir, exclude): self.tmpDir=tempfile.TemporaryDirectory() logging.debug(f'making tmp file from {srcDir} at {self.tmpDir.name}') self.path=self.tmpDir.name+'/'+Path(srcDir).resolve().name - self.ignorePattern=shutil.ignore_patterns('*.adoc', '.git', '.gitignore') + self.ignorePatterns=['*.adoc', '.gitignore', '.git/*'] + self.ignorePatterns.extend(exclude) + self.ignorePattern=shutil.ignore_patterns(*self.ignorePatterns) shutil.copytree(srcDir, self.path, ignore=self.ignorePattern, symlinks=False) #copy out from tmpDir (which may be in RAM, depending on distrubution) to disk @@ -92,9 +95,9 @@ def convert_file(inDir, outDir, inFile): logging.error(f'stdOut was {e.stdout}') if __name__ == '__main__': - inFile, outFile, compress=parse_arguments() + inFile, outFile, compress, exclude=parse_arguments() os.chdir(inFile) - tmpDir=TmpDir('./') + tmpDir=TmpDir('./', exclude) pathsToConvert=find_paths_to_convert('*.adoc') for i in pathsToConvert: diff --git a/README.md b/README.md index e95c43b..9d81680 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,18 @@ ![Licence](https://img.shields.io/badge/Licence-GPL-blue) ## What is it? -ASCIIsite is a simple, barebones static site generator. You give it a directory contaning asciidoctor documents and supporing media in the strucutre you want your site to be in, and it spits out a fully functional static site based on that input directory. +ASCIIsite is a simple, bare bones static site generator. You give it a directory containing asciidoctor documents and supporting media in the structure you want your site to be in, and it spits out a fully functional static site based on that input directory. ## Usage -ASCIISite takes 2 (so far) optional arguments followed by the single mandatory arument telling it what directory to convert. +ASCIISite takes 2 (so far) optional arguments followed by the single mandatory argument telling it what directory to convert. the -o or --output option simply tells ASCIISite what to name the output file. +the --exclude flag allows you to specify a list of glob patterns. Any file matching these glob patterns will not be copied to the output. +This is helpful for any files that are needed for the compilation of the asciidoc files, but do not need to be in the final site. +The main use case I am aware of is files that are put into an asciidoc document via an include statement. + the -z or --compress flag tells ASCIISite to put the final product in a compressed tar.gz file as its output. This is especially useful if you are running ASCIISite on your personal computer, and will be uploading the tar.gz file to your server. @@ -29,7 +33,7 @@ test ├── images │   └── test_pattern.svg ├── include -│   └── include.adoc +│   └── include.txt └── landing_page.adoc ``` @@ -50,7 +54,25 @@ result ├── images │   └── test_pattern.svg ├── include -│   └── include.html +│   └── include.txt +└── landing_page.html +``` + +If, say, the include directory is a directory needed for the asciidoc compilation, +but not needed for the final website, you can use the --exclude option to specify a list of glob patterns to exclude. For example, +```` +ASCIIsite.py --exclude 'include*' -o output test +``` + +will get you an output like: +``` +result +├── dir +│   ├── collatz.py +│   └── subdir +│   └── linked.html +├── images +│   └── test_pattern.svg └── landing_page.html ``` diff --git a/tests/result/include/include.html b/tests/result/include/include.html deleted file mode 100644 index 74d8e07..0000000 --- a/tests/result/include/include.html +++ /dev/null @@ -1,552 +0,0 @@ - - - - - - - -included section - - - - - -
-
-

included section

-
-
-

Fusce maximus nec magna eu ultricies. -Fusce quis tellus vitae arcu facilisis lobortis. -Donec id erat at enim porta placerat in vitae sapien. -Duis justo arcu, hendrerit nec nulla eu, dictum dapibus ipsum. -Sed fermentum id elit eget fringilla. -Suspendisse volutpat imperdiet justo, ut efficitur odio maximus et. -Nunc interdum sollicitudin eros sit amet convallis. -Praesent volutpat tempus metus id tincidunt. -Proin aliquet justo a fermentum consectetur. -Nunc scelerisque, nisi id scelerisque dictum, nibh lectus ultrices nunc, quis ultricies erat velit sit amet urna. -Maecenas orci felis, volutpat at bibendum ut, mattis eu justo.

-
-
-

blocks

-
-
listing block
-
-
example of _listing block_
-with verbatim line break
-
-
-
-
Example 1. example block
-
-
-

example block -with line break

-
-
-
-
-
literal block
-
-
_literal_ block
-with line break
-
-
-pass block -with underlined text -
-
quote block
-
-
-

quote block -with line break

-
-
-
-
-
-
sidebar block
-
-

sidebar block -with line break

-
-
-
-
- - - - - -
-
Note
-
-
-

This is an example of an admonition block.

-
-
-

Unlike an admonition paragraph, it may contain any AsciiDoc content. -The style can be any one of the admonition labels:

-
-
-
    -
  • -

    NOTE

    -
  • -
  • -

    TIP

    -
  • -
  • -

    WARNING

    -
  • -
  • -

    CAUTION

    -
  • -
  • -

    IMPORTANT

    -
  • -
-
-
-
-
-
-
-
- - - \ No newline at end of file diff --git a/tests/test/include/include.adoc b/tests/test/include/include.txt similarity index 100% rename from tests/test/include/include.adoc rename to tests/test/include/include.txt diff --git a/tests/test/landing_page.adoc b/tests/test/landing_page.adoc index 0a4b2f5..ea59699 100644 --- a/tests/test/landing_page.adoc +++ b/tests/test/landing_page.adoc @@ -131,4 +131,4 @@ It's designed for: |=== -include::{includedir}/include.adoc[] +include::{includedir}/include.txt[]