11from __future__ import annotations
2- from typing import TYPE_CHECKING , List , Dict , Tuple
2+ from typing import TYPE_CHECKING , List , Dict , Tuple , Optional
33from os .path import dirname , basename , join
44from os import walk
55import tomllib
1919
2020class BuildMetaInfo :
2121
22- def __init__ (self , environment : str ) -> None :
23- self .environment = environment
22+ def __init__ (self , config : SyrinxConfiguration ) -> None :
23+ self .environment = config .environment
24+ self .domain = config .domain
2425 self .timestamp = datetime .now (tz = UTC )
2526 self .syrinx_version = version ('syrinx' )
2627
@@ -33,6 +34,7 @@ class ContentNode:
3334 front : Dict [str , str ]
3435 sequenceNumber : int
3536 buildPage : bool
37+ path : str
3638 meta : BuildMetaInfo
3739
3840 def __init__ (self ):
@@ -47,6 +49,16 @@ def title(self) -> str:
4749 return self .front ['Title' ]
4850 else :
4951 return self .name .replace ('_' , ' ' ).title ()
52+
53+ @property
54+ def address (self ) -> Optional [str ]:
55+ if self .meta .domain is not None :
56+ return f'https://{ self .meta .domain } { self .path } /'
57+
58+ @property
59+ def lastModified (self ) -> Optional [str ]:
60+ return self .front .get ('LastModified' )
61+
5062
5163def reorder_children (node : ContentNode ):
5264 node .leaves = sorted (node .leaves , key = lambda n : (n .sequenceNumber , n .name ))
@@ -68,7 +80,7 @@ def read_file(fpath: str) -> Tuple[Dict, str]:
6880
6981def read (root_dir : str , config : SyrinxConfiguration ) -> ContentNode :
7082
71- meta = BuildMetaInfo (config . environment )
83+ meta = BuildMetaInfo (config )
7284 content_dir = join (root_dir , 'content' )
7385
7486 tree : Dict [str , ContentNode ] = dict ()
@@ -98,14 +110,16 @@ def read(root_dir: str, config: SyrinxConfiguration) -> ContentNode:
98110 if ext != 'md' :
99111 continue
100112 name = fparts [0 ]
101-
113+
102114 fm_dict , md_content = read_file (join (dirpath , fname ))
103115
104116 if name == 'index' :
105117 node = indexNode
118+ node .path = dirpath .replace (content_dir , '' )
106119 else :
107120 node = ContentNode ()
108121 node .name = name
122+ node .path = join (dirpath .replace (content_dir , '' ), node .name )
109123 node .meta = meta
110124 indexNode .leaves .append (node )
111125
0 commit comments