improvements for *** splitting the body; and fix years
This commit is contained in:
parent
155fedb7b7
commit
6af00b14e0
13
event.py
13
event.py
@ -9,6 +9,7 @@ class Index( object ):
|
|||||||
self.path = path
|
self.path = path
|
||||||
self.fields = {}
|
self.fields = {}
|
||||||
self.doc = ""
|
self.doc = ""
|
||||||
|
self.updates = []
|
||||||
|
|
||||||
def path_short( self ):
|
def path_short( self ):
|
||||||
# XXX needs tidy
|
# XXX needs tidy
|
||||||
@ -24,7 +25,7 @@ class Index( object ):
|
|||||||
---
|
---
|
||||||
%(md)s
|
%(md)s
|
||||||
''' % { 'yaml': yaml.dump( self.fields, default_flow_style = False ),
|
''' % { 'yaml': yaml.dump( self.fields, default_flow_style = False ),
|
||||||
'md': self.doc,
|
'md': "\n\n***\n\n".join( [ self.doc ] + self.updates ),
|
||||||
} )
|
} )
|
||||||
outfile = open( self.path, 'w', encoding = "utf-8" )
|
outfile = open( self.path, 'w', encoding = "utf-8" )
|
||||||
outfile.write( outdata )
|
outfile.write( outdata )
|
||||||
@ -34,8 +35,10 @@ class Index( object ):
|
|||||||
indata = open( self.path, 'r', encoding = "utf-8" ).read()
|
indata = open( self.path, 'r', encoding = "utf-8" ).read()
|
||||||
( pre, yamldata, docdata ) = re.split( "^---$", indata, flags = re.MULTILINE )
|
( pre, yamldata, docdata ) = re.split( "^---$", indata, flags = re.MULTILINE )
|
||||||
self.fields = yaml.load( yamldata, Loader = yaml.SafeLoader )
|
self.fields = yaml.load( yamldata, Loader = yaml.SafeLoader )
|
||||||
self.doc = docdata.strip()
|
doc = docdata.strip()
|
||||||
|
bits = re.split( r"^\**$", doc, flags = re.MULTILINE )
|
||||||
|
self.doc = bits.pop( 0 )
|
||||||
|
self.updates = [ x.strip() for x in bits ]
|
||||||
|
|
||||||
def _toggle( self, fieldname ):
|
def _toggle( self, fieldname ):
|
||||||
if self.fields.get( fieldname ):
|
if self.fields.get( fieldname ):
|
||||||
@ -91,8 +94,8 @@ class Event( Index ):
|
|||||||
self.fields[ '$slug' ] = slug
|
self.fields[ '$slug' ] = slug
|
||||||
|
|
||||||
def set_year( self, year ):
|
def set_year( self, year ):
|
||||||
if not self.fields.get( 'year' ):
|
if isinstance( self.fields.get( 'year', None ), ( type( None ), str ) ):
|
||||||
self.fields[ 'year' ] = year
|
self.fields[ 'year' ] = int( year )
|
||||||
|
|
||||||
def set_published( self, published ):
|
def set_published( self, published ):
|
||||||
if not self.fields.get( '$date' ):
|
if not self.fields.get( '$date' ):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user