Simplify Permalink/Permaview URLs (#7729)

* 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 ca1e5cf387.
This commit is contained in:
Scott Sauyet
2023-11-21 11:24:17 +00:00
committed by GitHub
parent 9012d36859
commit 145a8d6992
3 changed files with 151 additions and 7 deletions
+7 -7
View File
@@ -122,10 +122,10 @@ function openStartupTiddlers(options) {
var hash = $tw.locationHash.substr(1),
split = hash.indexOf(":");
if(split === -1) {
target = $tw.utils.decodeURIComponentSafe(hash.trim());
target = $tw.utils.decodeTWURITarget(hash.trim());
} else {
target = $tw.utils.decodeURIComponentSafe(hash.substr(0,split).trim());
storyFilter = $tw.utils.decodeURIComponentSafe(hash.substr(split + 1).trim());
target = $tw.utils.decodeTWURITarget(hash.substr(0,split).trim());
storyFilter = $tw.utils.decodeTWURIList(hash.substr(split + 1).trim());
}
}
// If the story wasn't specified use the current tiddlers or a blank story
@@ -198,19 +198,19 @@ function updateLocationHash(options) {
// Assemble the location hash
switch(options.updateAddressBar) {
case "permalink":
$tw.locationHash = "#" + encodeURIComponent(targetTiddler);
$tw.locationHash = "#" + $tw.utils.encodeTiddlerTitle(targetTiddler);
break;
case "permaview":
$tw.locationHash = "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList));
$tw.locationHash = "#" + $tw.utils.encodeTiddlerTitle(targetTiddler) + ":" + $tw.utils.encodeFilterPath($tw.utils.stringifyList(storyList));
break;
}
// Copy URL to the clipboard
switch(options.copyToClipboard) {
case "permalink":
$tw.utils.copyToClipboard($tw.utils.getLocationPath() + "#" + encodeURIComponent(targetTiddler));
$tw.utils.copyToClipboard($tw.utils.getLocationPath() + "#" + $tw.utils.encodeTiddlerTitle(targetTiddler));
break;
case "permaview":
$tw.utils.copyToClipboard($tw.utils.getLocationPath() + "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList)));
$tw.utils.copyToClipboard($tw.utils.getLocationPath() + "#" + $tw.utils.encodeTiddlerTitle(targetTiddler) + ":" + $tw.utils.encodeFilterPath($tw.utils.stringifyList(storyList)));
break;
}
// Only change the location hash if we must, thus avoiding unnecessary onhashchange events