Oben Sonne  committed 678f737

Propagate command line options to pages and macros

  • Participants
  • Parent commits 8ed8a40

Comments (0)

Files changed (1)

     _re_eom = r'^---+ *\n?$'
     _sec_macros = "macros"
-    def __init__(self, path, strip, enc_in):
+    def __init__(self, path, strip, opts):
         """Create a new page.
         @param path: full path to page input file
         @param strip: portion of path to strip from `path` for deployment
-        @param enc_in: encoding of page input file
+        @param opts: command line options
         base = os.path.splitext(path)[0]
         self.path = "%s.html" % base
         self.macros = MacroDict(self)
+        self.opts = opts
-        with, 'r', enc_in) as fp:
+        with, 'r', opts.input_enc) as fp:
             self.raw = fp.readlines()
         # split raw content into macro definitions and real content
         # evaluate macro definitions
         tfname = ".page-macros.tmp"
-        with, "w", enc_in) as tf:
+        with, "w", opts.input_enc) as tf:
             tf.write("[%s]\n" % self._sec_macros)
-        with, "r", enc_in) as tf:
+        with, "r", opts.input_enc) as tf:
             cp = SafeConfigParser()
 # build site
-def build(project, base_url, enc_in, enc_out):
+def build(project, opts):
     """Build a site project."""
     RE_MACRO_FIND = r'(?:^|[^\\]){{ *([^}]+) *}}' # any macro
         for f in files:
             if, f): continue
             if os.path.splitext(f)[1] in (".md", ".markdown", ".mdown", ".mkd"):
-                page = Page(opj(cwd, f), dir_in, enc_in)
-                page.macros["base_url"] = base_url
+                page = Page(opj(cwd, f), dir_in, opts)
                 shutil.copy(opj(cwd, f), opj(dir_out, cwd_site))
         # expand reserved macros
         out = expand_macro(MACRO_CONTENT, out, skeleton)
-        out = expand_macro(MACRO_ENCODING, enc_out, out)
+        out = expand_macro(MACRO_ENCODING, opts.output_enc, out)
         # expand macros, phase 2 (macros used in page.html)
         out = expand_all_macros(out, page.macros)
             out = out.replace('src="%s"' % link, 'src="%s"' % based)
         # write HTML page
-        with, page.path), 'w', enc_out) as fp:
+        with, page.path), 'w', opts.output_enc) as fp:
     print("success: built project")