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
Simplify Permalink/Permaview URLs #7729
Simplify Permalink/Permaview URLs #7729
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I would be in favour of more readable characters in the links if it creates more human readable URLs |
The latest commit adds this feature. Now instead of
We can have
I have tried this with So for instance, we might have this permaview:
which is decent; it's hard to imagine better. But for permalinks, this is hard to beat:
CodeThe code is structured a little oddly for TW. Part of this is to enable us to easily try various combination of space characters and separators.:
These -- along with a list of punctuation characters allowed in fragments -- are then used to build a lookup object, and some regexes that are used to remove unwanted percent encoding, and to add our own space encoding. But this involves having a number of non-function variables inside the NoteI really didn't stress that this is not a panacea. There are plenty of URLs that will still have percent-encoding in them. Probably the worst offender will be the colon (
I really wish we could get around that, but I think the break in backward compatibility is too severe. |
The latest commit (0cabd09) fixes more of the ES6+ stuff added in the previous commit. It does one other thing. In the forum thread @AnthonyMuscio had this comment:
While I didn't get the full details of what he expects to be a problem, I did recognize that trailing sentence-ending punctuation is often not considered part of a link by many programs, assuming that that is part of the surrounding sentence. Thus
acts like it has a link to I originally used the tilde ( I haven't tested all the remaining characters yet to see if there are others besides There's one other major decision. Tony's concern above is probably not only about these sentence-enders. He would like this to be opt-in or opt-out, so that the current URL generation is still available. I understand the concern, but I'm loathe to do that. It certainly is possible, but I think it adds needless complexity. What do others think? |
And I just realized that this fixes an issue with the current permalink generation, which, while it converts |
@CrossEye -- at Talk you wrote:
I can assure you, that this contribution is valuable and appreciated by everyone here. -- As you wrote. Things move slowly in the core, especially if a change will be as visible for the end-users as this one is. Once it's merged and published, we have to live with it for a long time. Making things go away will have side effects for the community. As can be seen with v5.3.0, which only lived for several weeks and v5.3.1 was needed. So I hope this comment is encouraging We will also need to extend the documentation at: https://tiddlywiki.com/#PermaLinks |
I would also add that core development does tend to slow down for a while after a release, a natural consequence of the work and time commitment that each release takes. Also, I would recommend that for the future, directly creating an issue for a core improvement will move things along faster than posting on the community forums. I support the proposed change and will try to find time in the near future to review the implementation. Thank you for your work on this. |
There is 1 thing, we did not talk about yet: Non-Latin alphabets like Greek, Russian and so on. See the screenshot. If a tiddler is titled: заметка (note) the current URL is: But using the existing "slugify" mechanism it could be: Since I do not speak Russian or Greek I cannot say if this makes sense. But visually there is a big difference. Any idea about this one? |
Thank you @CrossEye, this is an ingenious solution to a long term blemish on TiddlyWiki's usability, and it is a great achievement to do so whilst retaining backwards compatibility. One minor point is that I think that new definitions in boot.js are not actually used until after all module loading has been completed, and so they can be moved to
I think that would make sense, yes.
That's a tricky one. Using Perhaps the difficulties of making such a change backwards compatible make it impractical?
The format for permalinks is the encoded title of the target tiddler followed by an optional colon and then a filter giving the tiddlers to display in the story (ie a permaview). The two parts can be given independently: https://tiddlywiki.com/#:[search[jeremy]]
We don't use map/filter/reduce, sadly. There has been some recent discussion about updating the JS dialect we use, but it has not been resolved yet.
This is a great PR, the top post is nice and clear, and the code has the hallmarks of being written for ease of comprehension, good stuff. |
Damn, I wrote a long response to everyone, in great detail, and think I must have left it in Preview mode when my machine needed to reboot. I will create it again soon, but I don't have the heart right now. In short, though, thanks for the encouragement! I will make (most of) the requested changes for my next commit. |
It is, very much so. Thank you very much!
Oops. I remembered to do this in my previous PR, but that was a tiny bug fix. Can't believe I forgot it here. I will include this in my next commit. (Tomorrow, I'm hoping.) |
I do understand. I created and help maintain a large project with varied periods of frenetic activity and others of relative quiescence.
Ok, I will probably get to that point eventually. But I don't have enough experience with the core to get a good sense of whether something is useful or has been considered and rejected or is extremely controversial. I'll get there, though.
Thank you. |
I think there's a real problem that this is not reversible. If we had a tiddler named But this is a serious problem you raise. My proposal will make for cleaner URLs, but only for those using the Latin alphabet. That's related to the specifications for URL fragment strings. It might be interesting to see if we can find a way to do this more readably, even if the generated URLs are not legally allowed, if they would work in any reasonable place that people use URLs. I've been mostly focused on the space and other punctuation, but perhaps if we do just generate https://tiddlywiki.com/#заметка and so long as the characters are letters, it would just work. I will have to think about this more. |
😊 Thank you. I should reiterate that there is one backward incompatible situation: if the user has laying around a permalink/view that was handcrafted and contains an
While I have no problem moving them, the existing code that I'm modifying/replacing is in
The latest incarnation uses
I will have to do more testing with these, but am not expecting any problems.
Understood. The Ramda library I founded and still sporadically maintain supports ES3! I guess I have some refactoring to do. Are there TW functions I can use in place of these? Could I write my own plain functional versions of them? Or should I just resort to
Thank you. I'm happy to hear it. |
A different idea altogetherI will try to make another commit tonight to address some issues, but I just had a thought about an entirely different permalink/view approach and wanted to see what people thought. I want to make it clear up front that I still prefer the version I've been coding. But I think this alternative is compelling enought to deserve some discussion. Use a short SHA-1 hashWe can make simple URLs that are not transparent but are short, easy to type, and would work everywhere by using one-way hashes of the titles, and then shorten them to a useful length. For instance, On loading with that URL, TW would scan tiddlers for one with a title whose SHA-1 title hash starts with that value. (If we use this elsewhere besides on load we should pre-cache the values.) This could be done in an entirely backwards-compatible manner if we signal this style url fragment with an initial character we wouldn't otherwise create in a URL. Here Possible extensionA possible extension of this idea would be to store this slug as a field in the tiddler, to be updated when the title changes. (I don't know just how fraught that might be, though.) But this could also let users override that slug for custom needs. ( DownsidesThere are two significant downsides I see:
QuestionIs this worth pursuing? I want to finish up the approach I'm working on. But is there something more compelling about this alternative that makes it worth following up in parallel? |
It was very much my pleasure. I learned a lot about TW in doing it! |
I am afraid I could not follow this whole process and change, but I just took the preview to test it, and see the safe I just created a tiddler with the underscore in the name and it creates a separate tiddler, but a permalink will only open the one with spaces. And fail if that is deleted, even if the underscore version is available.
I have not explored the use of other characters at this point. never the less thanks @CrossEye for your effort. |
Yeah, this is a flaw I should have seen. I will try a trick to alleviate it. Probably tomorrow, but maybe not until Sunday. We knew that this was not entirely backward compatible, but this is a bigger gap than expected. I think I can get this close enough not to matter as a practical concern.
I'm quite loathe to do this, unless absolutely necessary. Technically it would not be very difficult, but maintaining both behaviors feels like bloat. |
I think it should be easy to test, if a tiddler with spaces exists and then test if tiddlers with underscores exist. The only problem is, that every combination has to be tested. Starting with one which has underscores instead of spaces, which is the most likely one |
Hi @CrossEye. I'm afraid I'm going to revert this PR for the moment due to the backwards compatibility issues. We'll return to it for v5.3.3 |
This reverts commit 145a8d6.
Reverted in 0716ed4 I should add that even if this were to be fixed now, I think it would be unwise to rush it into this release. I would also prefer to have tests for the encoding/decoding functions. |
I'd really rather avoid that. I believe the URL conversion should not depend on the actual tiddler names in the wiki. I'm thinking that I can double-up underscores to represent single underscores. There is still a backward incompatibility, but it is a much less likely scenario: if you have spaces next to underscores in titles, then there is an ambiguity between If we don't want to accept this incompatibility, then I would prefer to go with Tony's suggestion of a toggle for the behavior, so that you can revert to percent-encoding. I don't like the idea of continuing to support both, but I'm far too new to the dev community to argue too hard against it. And I would definitely prefer it to testing for the existence of any of the 2n potential matching tiddlers.
Of course. I'm disappointed, but it's definitely the right call.
Yes, I did forget to ask about that. I didn't see tests anywhere near the root of repo, so thought there was probably not much of a test suite. Now I see there's a dedicated edition -- a fascinating concept! When I revisit this, I'll convert my personal mocha tests to match the style. |
Would it not be adequate to simply test for a tiddler with underscores and open it, otherwise open the equivalent with spaces as if it were underscores? Ie if someone has gone out of there way to use underscores in the tiddler title it will open them. If not they will have a link generated from new permalink (now containing underscores) to open the tiddler by the same name with spaces. To me this is adequate if documented, it even allows underscore tiddlers to be generated specifically to intercept a link incoming with underscores if desired. As I suggested earlier this will allow you to maintain a destination url even when the tiddler title needs to change within the wiki.
|
There's no perfect solution. I would live with this if we had to, but as I replied to @pmario, I believe the URL conversion should not depend on the actual tiddler names in the wiki. It also would have a problem with a tiddler title like My current thinking, which seems quite possible, and I will try it soon, is to convert this to
and then possibly add the flag you were suggesting earlier, the one I didn't and still don't really like, but which would let people exit this new behavior if they have a need to mix underscores and spaces together or have titles with consecutive spaces.
This is a fascinating concept. I can definitely see the uses for it. But I think if we want this, we should have an explicit mechanism for it, and not depend upon a convention about spaces and underscores. To me that mechanism sounds simple both to write and to configure. It would probably run before the decode above and might use dictionary tiddlers something like this:
or the equivalent in JSON. (Please excuse any lapses in biological taxonomy!) |
There should be no option to deactivate the new behaviour. IMO it only creates confusion. |
That would be my preference too. I would only be willing to do this if it's the only way to make this change widely acceptable. Otherwise we should treat it as a break with past behavior. Here's there's significant backward compatibility because -- except in some narrow cases we've been discussing -- older permalinks will still keep working. New ones would look different, true, but that doesn't cause issue with the existing ones. |
IMO there is an other way to handle it. As soon as there is an underscore in the tiddler title use the "old behaviour" for this tiddler. So users with underscores in their titles can change them if they want or stay with the old behaviour. -> Done. |
This seems far simpler to me than the responses raise. If a url is given, then open the tiddler to which it refers whether it has underscores or not. Now if such a tiddler is not found as per this activity, look to open the same tiddler where the underscores are replaced with spaces. A wiki already using underscored tiddlers (for whatever reason will still work), urls that "permalinks containing spaces, to one containing underscores" will; also open the "required tiddler.
This side effect is unlikely to cause problems because it relates to legacy wikis, only "if you upgrade to a wiki containing these new permalinks is it even a question?" and the preference is for backward compatibility. However this side effect is a feature and can be called out as such a feature and documented, thereby not becoming a problem but a feature.
My preference here is driven by a reasonably deep understanding of search Engin optimisation, maintaining valid links, website publishing and more so please take my appeal seriously, especially since this is a core change, that sets a standard, we need to maintain indefinatly, to support backward compatibility. |
I wish we could. The reason that we're having this discussion, though, is that the "old behavior" does not do anything to the underscore characters. They were not percent-encoded. So we would have no way to distinguish between |
That reduces the problem, but doesn't eliminate it. Again, if we were to try to load the url https://tiddlywiki.com/#Team_decided_to_WONT_FIX_the_issue, we could well find that there is no tiddler titled Again, maybe it's mostly a philosophical issue, but I think that we really would prefer our encoded fragment to represent a single title, and not multiple ones depending upon what titles happen to be present in the current wiki.
The backward compatibility I've been striving for is simply that legacy permalinks/views should continue to properly load the appropriate tiddlers. You have correctly demonstrated that there was a potentially larger class of permalinks for which this would fail with my first code. I'm simply trying to reduce the damage. Your suggestion gets us part-way there. It may be our best bet, but it introduces an intellectual overhead I'd like to avoid. |
@CrossEye I think the goal needs to be ensuring that a permalink only maps to a single tiddler title while maximizing backwards compatibility. We should reconsider the original proposal of using the |
Hi @CrossEye thanks for your patience with this. To add to @saqimtiaz's comment, it is also very important that neither the encoding nor decoding should depend on the state of the tiddler store. In other words, encode/decode must be pure functions. |
I think with a + my suggestion from #7729 (comment) could work. |
If spaces are changed to underscore in the custom permalinks existing underscores remain untouched there is no complexity here. Test for the incomming tiddler titles and if it does not exist translate it to the new permalink form and open that. |
* Simplify Permalink/Permaview URLs * Fix lint warnings by removing arrow functions * Remove commented sample code * Remove post-ES5 code * Add many more allowable non-percent-encodedcharacters * Fix more ES6+ stuff, add end-of-sentence padding character. * Fix to match standards * Move the new code from boot to util * Change from custom map/filter to $tw.utils.each * Make `each` blocks multi-line * Move the permalink handling to its own file * Remove auto-navigation * Revert "Remove auto-navigation" This reverts commit ca1e5cf.
This reverts commit 145a8d6.
@CrossEye -- I think this PR still has value. We should change the On the other hand, it will never be backwards compatible, since we only restrict 5 characters @Jermolene -- If we would like to go with |
Yes, that was my thought too. I expect to get to this next weekend, if not before.
Because the current mechanism converts This is a much smaller issue that what happens with
That isn't necessary. We will continue to encode |
I personally did remove spaces from my tiddler titles and use "titles-with-hyphens" instead. So with the new mechanism I would probably be able to go back to have "titles with spaces" again. -- may be :) IMO you should change the char to + and create a new PR. |
New version in #7990 |
Closes #7728
We create new functions for encoding and decoding the fragment (hash) portion of a URL, so that what would previously have been encoded as
https://tiddlywiki.com/#Foo%20Bar%20Baz
can now be encoded ashttps://tiddlywiki.com/#Foo+Bar+Baz
andhttps://tiddlywiki.com/#Foo%20Bar%20Baz:%5B%5BFoo%20Bar%20Baz%5D%5D%20Qux%20%5B%5BCorge%20Grault%5D%5D
can becomehttps://tiddlywiki.com/#Foo+Bar+Baz:Foo+Bar+Baz&Qux&Corge+Grault
.This does not try to capture any additional punctuation. If it appears in a tiddler title, it will still be percent-encoded. There is a reasonably strong argument for keeping intact any punctuation the specification allows, excepting the
+
,:
, and,
this format claims. That would be a fairly simple extension of this PR.Note that this is intended to not break any existing permalinks/permaviews. Those should continue to work as they have. There is one minor unavoidable caveat there. Although TiddlyWiki would not have generated a perma-link/view that included a
+
sign, it's possible that someone hand-crafted such a url for a tiddler with a+
in its title. That link would no longer work.Open Questions
-
,.
,_
,~
,!
,$
,'
,(
,)
,*
,;
,=
, and@
. This would mean many fewer ugly percent-encoded characters?&
to the much-less-likely one of~
?Array.prototype.map
andArray.prototype.filter
with other implementations?