Skip to content

Commit a32203c

Browse files
nodes have address property
1 parent cd6628a commit a32203c

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

meta/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset=utf-8>
55
<meta http-equiv=x-ua-compatible content="ie=edge">
66
<meta name=viewport content="width=device-width,initial-scale=1">
7-
<meta syrinx-environment="production" syrinx-timestamp="2025-09-21T19:45:17.663400+00:00" />
7+
<meta syrinx-environment="production" syrinx-timestamp="2025-09-21T23:06:55.050852+00:00" />
88

99
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.15.0/cdn/themes/light.css" />
1010
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.15.0/cdn/shoelace-autoloader.js"></script>

syrinx/read.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import TYPE_CHECKING, List, Dict, Tuple
2+
from typing import TYPE_CHECKING, List, Dict, Tuple, Optional
33
from os.path import dirname, basename, join
44
from os import walk
55
import tomllib
@@ -19,8 +19,9 @@
1919

2020
class 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

5163
def 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

6981
def 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

tests/read.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22
from unittest import TestCase
33
from unittest.mock import patch, Mock
4-
from datetime import datetime
54

65

76
class ReadTests(TestCase):
@@ -68,3 +67,23 @@ def test_read_adds_build_info(self, datetime, read_file, walk):
6867
self.assertEqual(root.meta.timestamp, datetime.now())
6968
self.assertEqual(root.branches[0].meta.environment, 'foo')
7069
self.assertEqual(root.branches[0].meta.timestamp, datetime.now())
70+
71+
@patch('syrinx.read.walk')
72+
@patch('syrinx.read.read_file')
73+
def test_read_address(self, read_file, walk):
74+
"""
75+
"""
76+
read_file.return_value = dict(), ''
77+
walk.return_value = [
78+
('/pth/content', None, ['index.md']),
79+
('/pth/content/foo', None, ['index.md', 'boz.md']),
80+
('/pth/content/foo/bar', None, ['index.md']),
81+
]
82+
from syrinx.read import read
83+
config = Mock()
84+
config.domain = 'loop.xyz'
85+
root = read('/pth', config)
86+
self.assertEqual(root.address, 'https://loop.xyz/')
87+
self.assertEqual(root.branches[0].address, 'https://loop.xyz/foo/')
88+
self.assertEqual(root.branches[0].branches[0].address,
89+
'https://loop.xyz/foo/bar/')

0 commit comments

Comments
 (0)