Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-19 11:19:36

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,750
Website

[request] Paragraphs have their own URL reference links.

I don’t know if this is a plugin, or what, but it’s a fantastic idea for anyone like me who researches content and often uses quotations. Check this site out, this article, for example, and note the little “#“s at the end of each paragraph. That’s fawking cool. Could that be done?

Offline

#2 2011-06-23 18:03:18

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: [request] Paragraphs have their own URL reference links.

I loves it too. I think it’s native to one of Mr Winer’s own systems, but I’m not sure which. Most of the time I can’t figure out what he’s on about. Would love to see a Txp plugin doing the same thing though.

Only problem I can see is the risk of link rot. I mean – what if you edited a live article and added paragraphs earlier in the body than a paragraph that had already been bookmarked/indexed/liked/tweeted/whatever? Small chance, but it feels a bit fragile.

Offline

#3 2011-06-23 18:37:04

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,750
Website

Re: [request] Paragraphs have their own URL reference links.

I don’t know if this would work, but one idea might be to generate paragraph IDs every 5th value (e.g., 0005, 0010, 0015, etc.) so that if you add a paragraph before or in between existing (“live”) paragraphs, it can be done without wrecking the existing values (i.e., 0003, 0005, 0010, 0012, 0015…). That gives 4 possible inserts between each existing pair of paras, which should be plenty for most post editorial work.

If a new para was added after all existing paras, it would just get a new value in the 5th sequence (e.g., 0020).

If a paragraph was deleted (e.g., 0005, 0010, 0015…), then any call to that just gets the default article url (effectively the top of article).

This would assume some things:

  1. The paragraph IDs are not added until an article is published live status.
  2. The IDs are more for providing unique URIs as opposed to reflecting a true numbering (paragraph count).
  3. The para IDs of each subsequent article start far enough ahead in a the numbering sequence as to not conflict with a previous article (e.g, maybe it jumps ahead by 10 from the last ID value).

I have no idea how changing an article’s publish date might affect the numbering assignment process for past vs. future article paragraphs.

It just occurs to me that if we wanted more of a count (#2 above), at least per article, then instead of a gap model like every 5th value, maybe it could add a letter to the preceding live value (i.e., 0005, 0005a, 0005b, 0006, 0007, 0007a, 0008). Any new paras at beginning of article would get an earlier value (e.g., 0004), and any at end an unused subsequent value (e.g, 0009…), made possible by rule #3 above.

Offline

#4 2011-06-23 19:02:03

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,367
Website GitHub Mastodon

Re: [request] Paragraphs have their own URL reference links.

Something is making me think of the color purple. I thought was the really cool back at the time, even if some people found it Useful but unrealistic. I remember getting it implemented on some site once but the details are a bit foggy.

I wonder if this WordPress plugin might be useful.

Offline

#5 2011-06-23 19:33:36

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [request] Paragraphs have their own URL reference links.

Nice ideas everyone :)

You could easily do that per article basis with JavaScript. Using jQuery:

$(document).ready(function() {
	$('#myArticleContainer > p').each(function(index) {

		/*
			Add unique ID to each paragraph.
		*/

		$(this).attr('id','p'+index);

		/*
			Add links at the end of every paragraph
		*/

		$(this).append('<a href="#p'+index+'" title="This paragraph">#</a>');
	});
});

Untested, hopefully works. Might hack and slash the used server down even that it’s not server side snippet. Yeah it’s that bad. #myArticleContainer would be the parent container holding paragraphs.

michaelkpate wrote:

I wonder if this WordPress plugin might be useful.

By looking the plugin, it seems to do pretty same as the code I posted above. It’s JavaScript based snippet.

Destry wrote:

I don’t know if this would work, but one idea might be to generate paragraph IDs every 5th value (e.g., 0005, 0010, 0015, etc.) so that if you add a paragraph before or in between existing (“live”) paragraphs, it can be done without wrecking the existing values (i.e., 0003, 0005, 0010, 0012, 0015…). That gives 4 possible inserts between each existing pair of paras, which should be plenty for most post editorial work.

But how does it know what paragraph was which before modification? The paragraphs would still change, and additional paragraphs would shift the count.

Easiest method of keeping the paragraph ID static, non-changing, as long as the content stays same, is to generate checksum (hash) from the content. For example by using md5. If the content of the paragraph changes, the permlink changes. If it stays same, the permlink stays same, no matter what is added to the article.

Ideally this would have to be done during article save and stored in the database as it would take too long to generate checksum on every page request. Unfortunately it might not as hassle free to do as it sounds — Textpattern lacks some callbacks that would make it really easy. It’s possible, could be done by hooking to article panel, watching when article is saved and then updating the saved article, placing IDs and links to every paragraph.

I have no idea how changing an article’s publish date might affect the numbering assignment process for past vs. future article paragraphs.

I don’t see how it would effect it at all, as the paragraphs only have anchors. The publishing date would effect the links only if the permlink mode used for articles uses the publishing date.

The para IDs of each subsequent article start far enough ahead in a the numbering sequence as to not conflict with a previous article (e.g, maybe it jumps ahead by 10 from the last ID value).

The link would always include the article permlink and the paragraph would just have anchor. If you want unique anchor too, just prefix the anchor (md5 checksum) with the article’s ID and that’s it. Problem solved.

Last edited by Gocom (2011-06-23 19:43:53)

Offline

#6 2011-06-23 22:43:22

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,153
Website

Re: [request] Paragraphs have their own URL reference links.

Just remember, once you install such a plugin, you have to say something of lasting value in every sentence.

On a more serious note, doesn’t google code (or another site along those lines) allow you to bookmark a particular line and even column of source code. Surely it can’t have an anchor around every single character?


TXP Builders – finely-crafted code, design and txp

Offline

#7 2011-06-23 23:04:28

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [request] Paragraphs have their own URL reference links.

jakob wrote:

On a more serious note, doesn’t google code (or another site along those lines) allow you to bookmark a particular line and even column of source code. Surely it can’t have an anchor around every single character?

Sure it does. If an anchor directs something, then there is something that has that particular ID, or either there is (JavaScript) snippet that does the exact same thing on fly when detecting hash in the requested URI (for example in case of a word, counting the correct word and then directing there). Also server side languages can be used to do the job on fly in same manner as JavaScript. Counts correct location, and then throws an anchor ID there.

For example Google Code uses giant HTML tables where every actual row is a table row and columns hold all the needed IDs.

Last edited by Gocom (2011-06-23 23:15:34)

Offline

#8 2011-07-09 11:01:00

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: [request] Paragraphs have their own URL reference links.

Offline

#9 2013-03-22 11:26:14

etc
Developer
Registered: 2010-11-11
Posts: 4,331
Website GitHub

Re: [request] Paragraphs have their own URL reference links.

Server-side solution (the forum is a bit sleepy now): replace <txp:body /> with

<txp:etc_query data='<txp:body />'
 replace="//p@@id=p{$md5}@+= <a href='#p{@id?}'>#</a>" />

in the article form.

Edit: the upcoming 4.6 should make it possible on article save, to avoid server overload.

Last edited by etc (2013-03-22 13:14:45)

Offline

#10 2013-03-22 12:57:29

candyman
Member
From: Italy
Registered: 2006-08-08
Posts: 684

Re: [request] Paragraphs have their own URL reference links.

pieman wrote:

I loves it too. I think it’s native to one of Mr Winer’s own systems, but I’m not sure which.

Radio UserLand, I used it 9 years ago: now the support it’s over.

OT: I’ve always loved the way Radio Userland automaticallyCreatesTheUrls, very nice. How could it be done with Textpattern?

BTW, interesting reading.

Offline

#11 2013-03-22 13:14:25

etc
Developer
Registered: 2010-11-11
Posts: 4,331
Website GitHub

Re: [request] Paragraphs have their own URL reference links.

candyman wrote:

I’ve always loved the way Radio Userland automaticallyCreatesTheUrls, very nice. How could it be done with Textpattern?

It’s not really txp-specific, but technically, for (say) h4 permalinks, you could use something like

<txp:etc_query data='<txp:body />'
 replace="//h4@@id={$strip_tags.ucwords.str_replace( ||$)}@+= <a href='#{@id?}'>#</a>" />

Offline

#12 2013-03-22 13:52:43

candyman
Member
From: Italy
Registered: 2006-08-08
Posts: 684

Re: [request] Paragraphs have their own URL reference links.

This method takes into account the capital letter from the second word?
Many thanks for the tip, I’ll give a try!

Last edited by candyman (2013-03-22 13:55:43)

Offline

Board footer

Powered by FluxBB