Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve breadcrumbs to not abridge words #23

Open
saqimtiaz opened this issue Jun 26, 2021 · 5 comments
Open

Improve breadcrumbs to not abridge words #23

saqimtiaz opened this issue Jun 26, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@saqimtiaz
Copy link
Owner

From https://groups.google.com/g/tiddlywiki/c/-xTFWPwzq6g/m/K98n6_NZAgAJ

I have made the following tweak to the text display for the breadcrumbs. It's a very minor thing, but in my opinion looks nicer than just cutting off the title mid-word:

<$text text={{{ [<display-title>length[]compare:number:lt[40]then<display-title>] ~[<display-title>split[]first[40]join[]trim[]addsuffix[...]] }}}/>

That is definitely a nice idea. I wonder if we might take it a step further and just drop the last word (which may be incomplete). This is untested:

<$text text={{{ [<display-title>length[]compare:number:lt[40]then<display-title>] ~[<display-title>split[]first[40]join[]trim[]search-replace:g:regexp[(.*)\s(\w+)$],[$1]] }}}/>

@saqimtiaz saqimtiaz added the enhancement New feature or request label Jun 26, 2021
@saqimtiaz
Copy link
Owner Author

saqimtiaz commented Jun 26, 2021

Improvements on the filter expression:

[[Unlike conventional online services, TiddlyWiki lets you choose where to keep your data, guaranteeing that in the decades to come you will still be able to use the notes you take today.]search-replace:g:regexp[(.{40}).*],[$1]search-replace:g:regexp[(.*)\s(\w+)$],[$1]]

or

[[Unlike conventional online services, TiddlyWiki lets you choose where to keep your data, guaranteeing that in the decades to come you will still be able to use the notes you take today.]search-replace:g:regexp[^(.{30,45})\s.*$],[$1]]

The latter is potentially more brittle if there is no word boundary between 30th and 45th character.

@saqimtiaz
Copy link
Owner Author

Can also check for only whitespace in the text body and avoid the recursive macro while we are at it:


\whitespace trim
\define stream-show-breadcrumbs()
<$list filter="[<currentTiddler>has[stream-type]]">
	<$list filter="[<currentTiddler>get-stream-root:includeall[]]">
		<$wikify name="display-title" text={{{ [<currentTiddler>!is[binary]get[text]trim[]!is[blank]] ~[{!!title}] }}}>
			<span class="sq-breadcrumbs-fragment">
			<$link to=<<currentTiddler>>>
				<$text text={{{ [<display-title>split[]first[50]join[]] }}}/>
			</$link>>
			</span>
		</$wikify>
	</$list>
</$list>
\end
<$list filter="[{$:/config/sq/streams/enable-breadcrumbs}match[yes]]" variable="_NULL">
<<stream-show-breadcrumbs>>
</$list>

This does not include the above breadcrumb improvements. Also, use :reduce.

@zhangxiubo
Copy link
Contributor

zhangxiubo commented Jul 1, 2021

One thing I have noted when tweaked this macro myself for improved readability was that just testing whether text field is blank can occasionally lead to a blank fragment when the wikified text field is "effectively" blank, e.g. when the tiddler only contains a image tag or some macros.

To circumvent the issue, I prepared a regex pattern that detects some common non-blank content. The breadcrumb shall only fall back to using the title field if the text field appears to contain effectively blank content:

<$set name="pattern" value="^\s*(\w|\[\[|`|''|//|__)">
  <$wikify name="display-title" text={{{ [<currentTiddler>!is[binary]regexp:text<pattern>get[text]] ~[{!!title}] }}}>
    <span class="sq-breadcrumbs-fragment">
    <$link to=<<currentTiddler>>>
      <$text text={{{ [<display-title>split[]first[50]join[]] }}}/>
    </$link>>
    </span>
  </$wikify>
</$set>

@saqimtiaz
Copy link
Owner Author

@zhangxiubo thank you for the input, it is very helpful.

You have helped me to realize that there is a better way to check for blank fragments, since wikify will always return plain text. So we should check if the text is blank after we wikify. This will be more reliable and accurate than a regular expression.

Something like this (untested):


<$wikify name="display-title" text={{{ [<currentTiddler>!is[binary]get[text]trim[]] }}}>
	<span class="sq-breadcrumbs-fragment">
	<$link to=<<currentTiddler>>>
		<$text text={{{ [<display-title>!is[blank]else<currentTiddler>split[]first[50]join[]] }}}/>
	</$link>>
	</span>
</$wikify>

@zhangxiubo
Copy link
Contributor

@saqimtiaz That's definitely a better solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants