Skip to content

Commit

Permalink
Enable creating posts within container and setting up default layout
Browse files Browse the repository at this point in the history
  • Loading branch information
fantastic001 committed Feb 26, 2019
1 parent d1c9579 commit 4e876b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/JekyllPost.py
Expand Up @@ -24,6 +24,12 @@ def get_title(self) -> str:
return self._post_title.replace("\"", "")
except AttributeError:
return ""

def get_layout(self):
try:
return self._post_layout
except AttributeError:
return "post"

def get_contents(self) -> str:
try:
Expand All @@ -46,7 +52,12 @@ def set_contents(self, contents):
def set_string_date(self, string_date):
self._post_date = string_date

def set_layout(self, layout):
self._post_layout = layout

def save(self):
if not hasattr(self, "_post_layout"):
self._post_layout = "post"
f = open(self.file_path, "w")
f.write("---\n")
for attr in dir(self):
Expand Down
7 changes: 6 additions & 1 deletion src/JekyllPostContainer.py
@@ -1,10 +1,15 @@

from .JekyllPost import *
import os
import os.path

class JekyllPostContainer:
def __init__(self, dir_path):
self.dir_path = dir_path
self.posts = list([JekyllPost(dir_path + "/" + filename) for filename in os.listdir(dir_path)])

def get_posts(self):
return self.posts
return self.posts

def get_post(self, name):
return JekyllPost(os.path.join(self.dir_path, name + ".md"))
12 changes: 12 additions & 0 deletions src/JekyllSite.py
@@ -0,0 +1,12 @@
from .JekyllPostContainer import *
import os
import os.path
class JekyllSite:

def __init__(self, site_path):
self.site_path = site_path

def get_post_container(self):
return JekyllPostContainer(os.path.join(self.site_path, "_posts"))


3 changes: 2 additions & 1 deletion src/__init__.py
@@ -1,2 +1,3 @@
from .JekyllPost import *
from .JekyllPostContainer import *
from .JekyllPostContainer import *
from .JekyllSite import *

0 comments on commit 4e876b5

Please sign in to comment.