Jump to content

Request: Mapping from old single-post links to new format?


Kurkistan

Recommended Posts

It looks like in the transition from the old site to the new the way that individual-post links within threads are formatted has changed.

Before, if I wanted to link to a post about Peter confirming Hoid drinking metal, I'd get this:
http://www.17thshard.com/forum/topic/6411-hoids-powers-from-around-the-cosmere/#entry104532

Now the link to that post is this:
http://www.17thshard.com/forum/topic/6411-hoids-powers-from-around-the-cosmere/#comment-104532

Clicking on that first link will bring you to the thread, while the second will properly bring you to the specific post. Obviously the numbers are the same, so would it be possible to do some parsing here and convert "entryX" URLs into "comment-X" URLs when people navigate to them? As is there are a fair number of old links/bookmarks that aren't very helpful because they go to threads rather than posts.

Link to comment
Share on other sites

I believe there's a way to do it more intelligently than just with JavaScript (the existence of this massive MSDN page suggests as much, though I haven't read through it), but if you execute this JS code then it works.

if (window.location.hash && window.location.hash.slice(1,6) === "entry")
{
	window.location.hash = "comment-" + window.location.hash.slice(6);
}

EDIT:

There's obviously some level of link parsing (though on reflection this is more of query-resolving) already being done by IPB, or else the links in emails wouldn't work. When I clicked on the email alert for your post, I got this link:

http://www.17thshard.com/forum/topic/56107-request-mapping-from-old-single-post-links-to-new-format/?do=findComment&comment=491781

That gets parsed into the appropriate:

http://www.17thshard.com/forum/topic/56107-request-mapping-from-old-single-post-links-to-new-format/#comment-491781

 

Edited by Kurkistan
Link to comment
Share on other sites

On 2016-09-30 at 3:39 PM, Kurkistan said:

I believe there's a way to do it more intelligently than just with JavaScript (the existence of this massive MSDN page suggests as much, though I haven't read through it), but if you execute this JS code then it works.


if (window.location.hash && window.location.hash.slice(1,6) === "entry")
{
	window.location.hash = "comment-" + window.location.hash.slice(6);
}

 

I don't know javascript, but I think this breaks if there is a thread with "entry" in the title.

Link to comment
Share on other sites

4 hours ago, Eki said:

I don't know javascript, but I think this breaks if there is a thread with "entry" in the title.

Likely if we went the JS route there'd need to be some tweaking/testing to be sure (for one thing I'm not sure that window or window.location always necessarily exists, since I haven't dealt with it before), but that specific concern shouldn't be a problem. The "hash" by my understanding, is entirely the text that follows after the '#' at the end of the URL.

window.location for this thread, for instance, has an empty hash if you just click on the thread link itself rather than navigating to an individual post:

Location {hash: "", search: "", pathname: "/forum/topic/56107-request-mapping-from-old-single-post-links-to-new-format/", port: "", hostname: "www.17thshard.com"…}

 

Link to comment
Share on other sites

If you aren't sure of it, you could make it look for the string from the end of the URL backwards, and if it doesn't find it within a certain number of characters, just stops looking. There has to be a limit to how large the comment can be, so just look back as far as necessary. You can also add in qualifiers to make sure that it only executes if there are certain character types after the #comment. Overall, it should be an easy fix even if the .hash doesn't work the way you presented it as working. It is simple string conversion, right? I don't know javascript well enough to say, and I really don't know enough about how URLs work, but the coder in me says this should be easy.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...