From d59d75bc99929703a578823ed1f6cc00c1003e3d Mon Sep 17 00:00:00 2001 From: Geri Ochoa Date: Mon, 29 Aug 2022 14:46:46 -0400 Subject: [PATCH] Comment out synced files front matter Commenting out the front matter allows to reuse that content in other files where it may be relevant using the `readfile` shortcode. This doesn't affect the normal functionality of the YAML front matter. --- sync/sync.py | 4 ++++ sync/test_sync.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/sync/sync.py b/sync/sync.py index f7560e6..0777531 100755 --- a/sync/sync.py +++ b/sync/sync.py @@ -52,6 +52,8 @@ jinja_env = Environment(loader=FileSystemLoader(TEMPLATE_DIR)) FM_BOUNDARY = re.compile(r"^(?:)?", re.MULTILINE) YAML_SEPARATOR = "---\n" +FM_WRAPPER_OPEN = "\n" FOLDER_INDEX = '_index.md' @@ -226,9 +228,11 @@ def write_front_matter(target_doc, fm_doc, fm_config): fm_config = fm_config or {} fm_doc.update(fm_config) if fm_doc: + target_doc.write(FM_WRAPPER_OPEN) target_doc.write(YAML_SEPARATOR) YAML().dump(fm_doc, target_doc) target_doc.write(YAML_SEPARATOR) + target_doc.write(FM_WRAPPER_CLOSE) def transform_links_doc(text, base_path, local_files, rewrite_path, rewrite_url): """ transform all the links the text """ diff --git a/sync/test_sync.py b/sync/test_sync.py index 30c8989..a4853bb 100644 --- a/sync/test_sync.py +++ b/sync/test_sync.py @@ -342,11 +342,13 @@ class TestSync(unittest.TestCase): with tempfile.TemporaryDirectory() as site_dir: expected_result = os.path.join(site_dir, 'target', 'target.md') expected_content = ( + "\n" ) actual_result = transform_doc( self.doc, 'test-content', 'target.md', 'target', header, {}, @@ -389,10 +391,12 @@ class TestSync(unittest.TestCase): os.path.join(site_dir, 'target', 'test.txt')] template = ( + "\n" ) expected_contents = [template.format(weight=idx) for idx in range(2)] actual_results = transform_docs( @@ -423,10 +427,12 @@ class TestSync(unittest.TestCase): os.path.join(site_dir, 'target', 'test.txt')] template = ( + "\n" ) expected_contents = [template.format(weight=idx) for idx in range(2)] actual_results = transform_docs( -- GitLab