Skip to content

Commit bc7b86c

Browse files
committed
added config option main_page
also: - fixed searching for `CHANGELOG` too far up
1 parent c4a6f56 commit bc7b86c

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.15.0 - 2023-12-08
4+
5+
- added config option `main_page` (a.k.a. `USE_MDFILE_AS_MAINPAGE`)
6+
- fixed searching for `CHANGELOG` too far up the directory heirarchy (now stops when a `.git` folder is encountered)
7+
38
## v0.14.0 - 2023-11-25
49

510
- added the use of `*` wildcards in `implementation_headers`

src/poxy/fixers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,8 @@ class Links(HTMLFixer):
838838
__internal_doc_id = re.compile(r'^[a-fA-F0-9]+$')
839839
__local_href = re.compile(r'^([-/_a-zA-Z0-9]+\.[a-zA-Z]+)(?:#(.*))?$')
840840
__godbolt = re.compile(r'^\s*(?:https?[:]//)?(?:www[.])?godbolt[.]org/z/.+?$', re.I)
841-
__cppreference = re.compile(r'^\s*(?:https?[:]//)?(?:[a-z]+[.])?cppreference[.]com.*$', re.I)
842-
__named_req = re.compile(r'^\s*(?:https?[:]//)?(?:[a-z]+[.])?cppreference[.]com/w/cpp/named_req/.+?$', re.I)
841+
__cppreference = re.compile(r'^\s*(?:https?[:]//)?(?:[a-z]+[.])?cppreference[.]com/.*$', re.I)
842+
__named_req = re.compile(r'^\s*(?:https?[:]//)?(?:[a-z]+[.])?cppreference[.]com/.+?/named_req/.+?$', re.I)
843843

844844
def __call__(self, context: Context, doc: soup.HTMLDocument, path: Path):
845845
changed = False

src/poxy/project.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ class Context(object):
10501050
Optional(r'autolinks'): {str: str},
10511051
Optional(r'badges'): {str: ValueOrArray(str, name=r'badges', length=2)},
10521052
Optional(r'changelog'): Or(str, bool),
1053+
Optional(r'main_page'): Or(str, bool),
10531054
Optional(r'code_blocks'): CodeBlocks.schema,
10541055
Optional(r'cpp'): Or(str, int, error=r'cpp: expected string or integer'),
10551056
Optional(r'defines'): {str: Or(str, int, bool)}, # legacy
@@ -1560,7 +1561,11 @@ def add_internal_asset(p) -> str:
15601561
):
15611562
self.changelog = candidate_file
15621563
break
1563-
if self.changelog or candidate_dir.parent == candidate_dir:
1564+
if (
1565+
self.changelog
1566+
or candidate_dir.parent == candidate_dir
1567+
or (candidate_dir / '.git').exists()
1568+
):
15641569
break
15651570
candidate_dir = candidate_dir.parent
15661571
if not self.changelog:
@@ -1580,6 +1585,47 @@ def add_internal_asset(p) -> str:
15801585
self.changelog = temp_changelog_path
15811586
self.verbose_value(r'Context.changelog', self.changelog)
15821587

1588+
# main_page (USE_MDFILE_AS_MAINPAGE)
1589+
self.main_page = ''
1590+
if r'main_page' in config:
1591+
if isinstance(config['main_page'], bool):
1592+
if config['main_page']:
1593+
candidate_names = (r'README', r'HOME', r'MAINPAGE', r'INDEX')
1594+
candidate_extensions = (r'.md', r'.txt', r'')
1595+
as_lowercase = (False, True)
1596+
candidate_dir = self.input_dir
1597+
while True:
1598+
for name, ext, lower in itertools.product(
1599+
candidate_names, candidate_extensions, as_lowercase
1600+
):
1601+
candidate_file = Path(candidate_dir, rf'{name.lower() if lower else name}{ext}')
1602+
if (
1603+
candidate_file.exists()
1604+
and candidate_file.is_file()
1605+
and candidate_file.stat().st_size <= 1024 * 1024 * 2
1606+
):
1607+
self.main_page = candidate_file
1608+
break
1609+
if (
1610+
self.main_page
1611+
or candidate_dir.parent == candidate_dir
1612+
or (candidate_dir / '.git').exists()
1613+
):
1614+
break
1615+
candidate_dir = candidate_dir.parent
1616+
if not self.main_page:
1617+
self.warning(
1618+
rf'main_page: Option was set to true but no file with a known main_page file name could be found! Consider using an explicit path.'
1619+
)
1620+
1621+
else:
1622+
self.main_page = coerce_path(config['main_page'])
1623+
if not self.main_page.is_absolute():
1624+
self.main_page = Path(self.input_dir, self.main_page)
1625+
if not self.main_page.exists() or not self.main_page.is_file():
1626+
raise Error(rf'main_page: {config["main_page"]} did not exist or was not a file')
1627+
self.verbose_value(r'Context.main_page', self.main_page)
1628+
15831629
# sources (INPUT, FILE_PATTERNS, STRIP_FROM_PATH, STRIP_FROM_INC_PATH, EXTRACT_ALL)
15841630
self.sources = Sources(
15851631
config,

src/poxy/run.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,7 @@ def preprocess_doxyfile(context: Context):
195195
df.add_value(r'CLANG_OPTIONS', rf'-std=c++{context.cpp%100}')
196196
df.add_value(r'CLANG_OPTIONS', r'-Wno-everything')
197197

198-
home_md_path = None
199-
for home_md in (r'HOME.md', r'home.md', r'INDEX.md', r'index.md', r'README.md', r'readme.md'):
200-
p = Path(context.input_dir, home_md)
201-
if p.exists() and p.is_file():
202-
home_md_path = p
203-
break
204-
if home_md_path is not None:
205-
home_md_temp_path = Path(context.temp_pages_dir, r'home.md')
206-
copy_file(home_md_path, home_md_temp_path, logger=context.verbose_logger)
207-
df.set_value(r'USE_MDFILE_AS_MAINPAGE', home_md_temp_path)
198+
df.set_value(r'USE_MDFILE_AS_MAINPAGE', context.main_page)
208199

209200
df.append()
210201
df.append(r'# context.warnings', end='\n\n') # ---------------------------------------------------

src/poxy/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.14.0
1+
0.15.0

0 commit comments

Comments
 (0)