Parsing available files
This commit is contained in:
parent
1e7676f107
commit
d991c17cac
|
@ -4,7 +4,7 @@ import os
|
|||
import shutil
|
||||
import tempfile
|
||||
|
||||
from .models import Article
|
||||
from .models import Article, Section, Site
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
@ -17,22 +17,30 @@ def generate_site(input_path):
|
|||
|
||||
LOGGER.info("Processing static content to {}".format(root_directory))
|
||||
|
||||
for root, dirs, files in os.walk(root_directory):
|
||||
if "index.md" in files:
|
||||
# print(root.replace(root_directory, ""))
|
||||
site = Site(None)
|
||||
|
||||
for root, dirs, files in os.walk(root_directory):
|
||||
base_name = root.replace(root_directory, "")
|
||||
|
||||
categories = [x for x in base_name.split(os.sep) if x]
|
||||
|
||||
if "_index.md" in files:
|
||||
section = Section(categories[-1])
|
||||
elif "index.md" in files:
|
||||
with open(os.path.join(root, "index.md")) as md_file:
|
||||
content = md_file.read()
|
||||
|
||||
article = Article(content, None, None)
|
||||
article = site.add(content)
|
||||
article.write(os.path.join(root, "index.html"))
|
||||
else:
|
||||
LOGGER.warning(
|
||||
"{}: No `index.md` file found in this directory. You might want to add one.".format(
|
||||
"{}: No `index.md` or `_index.md` files found in this directory. You might want to add one.".format(
|
||||
root
|
||||
)
|
||||
)
|
||||
|
||||
site.write()
|
||||
|
||||
|
||||
def run(args=None):
|
||||
"""Copy the content located at `input_path`
|
||||
|
|
|
@ -33,7 +33,7 @@ class Article:
|
|||
self.meta, self.content = extract_metadata_from_content(file_content)
|
||||
self.title = self.meta.get("title")
|
||||
self.description = self.meta.get("description")
|
||||
self.tags = self.meta.get("tags")
|
||||
self.tags = self.meta.get("tags", [])
|
||||
self.file_name = file_name
|
||||
try:
|
||||
self.published_date = datetime.strptime(file_name[0:10], "%Y-%m-%d")
|
||||
|
@ -92,3 +92,10 @@ class Site:
|
|||
tag_key.append(article)
|
||||
|
||||
return article
|
||||
|
||||
def write(self):
|
||||
LOGGER.info("Writing site tags")
|
||||
...
|
||||
LOGGER.info("Writing site categories")
|
||||
...
|
||||
print(len(self.articles))
|
Loading…
Reference in New Issue