Skip to content

Commit

Permalink
fix: With RETAIN_PAGE_NAME_CASE enabled only the capitalization of th…
Browse files Browse the repository at this point in the history
…e filename determines the captialization of the Page name

- Adjusted tests.
- Added a section "Page name" to the Documentation/Help.

This fixes #193.
  • Loading branch information
redimp committed Jan 31, 2025
1 parent f930d44 commit 83dd439
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
11 changes: 9 additions & 2 deletions otterwiki/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Attachments will be moved with the renamed page.

A page (with all its attachments) can be deleted with <span class="help-button"><span class="btn btn-square btn-sm"><i class="fas fa-ellipsis-v"></i></span> <i class="fas fa-caret-right"></i> <span class="btn btn-square btn-sm"><i class="far fa-trash-alt"></i></span> Delete</span>. Please note: This deletion can be reverted. An Otter Wiki never makes the repository forget.

#### Page name

The page name can be anything that can be stored in the file system, with some sanitization: `?$.#\` and trailing slashes `/` will be removed.
Since all pages are stored in all lowercase filenames, the capitalization of the page name is determined by the first header.

Note: When `RETAIN_PAGE_NAME_CASE` is enabled, the capitalization of the filename determines the capitalization of the page name.

---

### Attachments
Expand All @@ -62,7 +69,7 @@ The pasted image will be uploaded and attached to the page you are editing.

#### Editing attachments

Open the attachment menu via <span class="help-button"><span class="btn btn-square btn-sm"><i class="fas fa-ellipsis-v"></i></span> <i class="fas fa-caret-right"></i> <span class="btn btn-square btn-sm"><i class="fa fa-paperclip"></i></span> Attachments</span>.
Open the attachment menu via <span class="help-button"><span class="btn btn-square btn-sm"><i class="fas fa-ellipsis-v"></i></span> <i class="fas fa-caret-right"></i> <span class="btn btn-square btn-sm"><i class="fa fa-paperclip"></i></span> Attachments</span>.
In addition to uploading, each attachment can also be opened via the <span class="help-button"><a hre="#"><i class="fas fa-edit"></i></a></span> for editing, which allows you to replace, rename or delete the attachment. The history of the attachment is displayed and offers the possibility to revert changes using <span class="help-button"><a hre="#"><i class="fas fa-undo"></i></a></span>.

#### Inline attached images
Expand Down Expand Up @@ -105,7 +112,7 @@ case</em> and <em>Regular expression</em>.</p>
### Page index

An overview about all pages is given by the Page index, you can open it with
<span class="help-button"><span class="btn btn-square btn-sm"><i class="fas fa-list"></i></span> A-Z</span> from the left sidebar. All listed pages are sorted by page name and
<span class="help-button"><span class="btn btn-square btn-sm"><i class="fas fa-list"></i></span> A-Z</span> from the left sidebar. All listed pages are sorted by page name and
grouped by their first letter.

To list the headings of all pages use the toggle on top of the page:
Expand Down
30 changes: 17 additions & 13 deletions otterwiki/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,23 @@ def get_pagename(filepath, full=False, header=None):
filepath = filepath[:-3]

arr = split_path(filepath)
for i, part in enumerate(arr):
hint = part
# if basename use header as hint
if i == len(arr) - 1 and header is not None:
hint = header
if (hint != part and hint.lower() == part.lower()) or (
hint == part and hint != part.lower()
):
arr[i] = hint
else:
arr[i] = (
part if app.config["RETAIN_PAGE_NAME_CASE"] else titleSs(part)
)
if app.config["RETAIN_PAGE_NAME_CASE"]:
# When RETAIN_PAGE_NAME_CASE is set the pagename is deduced by just the filename. No magic.
pass
else:
# When RETAIN_PAGE_NAME_CASE is not set, all files are lowercase, so headers can be used to
# configure a pagename. else default to titleSs
for i, part in enumerate(arr):
hint = part
# if basename use header as hint
if i == len(arr) - 1 and header is not None:
hint = header
if (hint != part and hint.lower() == part.lower()) or (
hint == part and hint != part.lower()
):
arr[i] = hint
else:
arr[i] = titleSs(part)

if not full:
return arr[-1]
Expand Down
10 changes: 6 additions & 4 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,18 @@ def test_get_pagename_raw(create_app_raw_filenames, req_ctx):
# updated version wich respects upper and lowercase
assert "ExamplE" == get_pagename("ExamplE")
assert "two words" == get_pagename("two words.md")
assert "Two words" == get_pagename("Two words.md")
assert "two Words" == get_pagename("two Words.md")
assert "two words" == get_pagename("two words")
assert "Two words" == get_pagename("Two words")
assert "Two words" == get_pagename("two words", header="Two words")
assert "two words" == get_pagename("two words", header="Two words")
# and with subdirectories
assert "Two words" == get_pagename("subdir/two words", header="Two words")
assert "Two words" == get_pagename(
assert "two words" == get_pagename("subdir/two words", header="Two words")
assert "two words" == get_pagename(
"subdir/two words.md", header="Two words"
)
assert "Two words" == get_pagename(
"subdir1/subdir2/two words.md", header="Two words"
"subdir1/subdir2/Two words.md", header="Two words"
)
assert "two words" == get_pagename("subdir1/subdir2/two words.md")
assert "Two Words" == get_pagename("subdir1/subdir2/Two Words")
Expand Down

0 comments on commit 83dd439

Please sign in to comment.