views:

42

answers:

2

I'm looking for a strategy for managing links within articles. The body of the article is saved in a database and pulled during page assembly. What all should be saved in the database to easily define and manage links?

Some purists believe that markup should NEVER be stored in the database. Some believe its ok in moderation. But to me, the notion of a link is almost inseparable from its html markup.

Is there a better, more succinct way of representing a link in an article (in a database) than simply embedding "anchor text"?

One idea I've kicked around involves embedding just enough markup to semantically describe areas of interest, and in a different table, map those notions to actual URLs. All encounters of a particular notion get wrapped with the link.

<p>Here is an example of a
<span class="external-reference semantic-web">semantic</span> 
approach to link management.</p>

A table then might associate the URL of the article and the key class of 'semantic-web' to a URL like http://en.wikipedia.org/wiki/Semantic%5FWeb

<p>Here is an example of a <span class="external-reference semantic-web">
<a href="http://en.wikipedia.org/wiki/Semantic_Web"&gt;semantic&lt;/a&gt;&lt;/span&gt; 
approach to link management.</p>

Things I like about this approach is that all my URLs are in one location in the database. I could technically change or remove links without touching the body of the article. I have very good class names for CSS.

I don't like having another table to maintain, and another step/phase in render time. It could slow down response time.

Are there any other strategies out there that provide superior link management?

A: 

There are a few attempts to do this that I have seen.

One way to do this is through URL redirects. You can implement a logic component on the server that will interpretate what the URL is requesting rather than a path to the content.

Another attempt is that the links orginally set to a reference value [which can be looked up in a database], and is requested at runtime/generation.

Regardless, you will have to reference the material that you wish to link to with some sort of identifier.

monksy
+1  A: 

You may want to look at templating (such as Smarty for PHP).

I agree that markup shouldn't normally be held in the database.

However, you might also consider implementing a "pointer" concept, where at each link, you break your storage of the page, add a pointer in the table to the link, then a pointer in the link table to the next segment of content for the page. (I have no idea how complicated that would be - just an idea.)

Or look at how various CMS tools handle the idea. Some just put everything in the database as one big block of text, while others rely on templating, and others may do something else entirely (like object-oriented environments such as Plone).

warren