forked from plone/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddMetaData.py
More file actions
43 lines (40 loc) · 1.18 KB
/
addMetaData.py
File metadata and controls
43 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import logging
metadata_check = """---
myst:
"""
metadata = """---
myst:
html_meta:
"description": ""
"property=og:description": ""
"property=og:title": ""
"keywords": ""
---
"""
logging.basicConfig()
logger = logging.getLogger("addMetaData")
logger.setLevel(logging.INFO)
logger.info("Add html_meta snippet if necessary.")
count_files = {
"modified": 0,
"unmodified": 0,
}
docs_dir = "./docs" if os.path.isdir("./docs") else "."
for root, dirs, files in os.walk(docs_dir):
for name in files:
if name.endswith(".md"):
filename = os.path.join(root, name)
# print(filename)
with open(filename, "r+") as f:
data = f.read()
if not data.startswith(metadata_check):
f.seek(0)
f.write(metadata)
f.write(data)
count_files["modified"] += 1
logger.info(f"{filename} html_meta prepended.")
else:
count_files["unmodified"] += 1
logger.info(f'html_meta snippet added to {count_files["modified"]} files.')
logger.info(f'{count_files["unmodified"]} files unmodified.')