English 中文(简体)
Is the concept of a link inseparable from its html markup?
原标题:

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_Web

<p>Here is an example of a <span class="external-reference semantic-web">
<a href="http://en.wikipedia.org/wiki/Semantic_Web">semantic</a></span> 
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?

最佳回答

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).

问题回答

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.





相关问题
What markup language to store in a DB?

Related: How to store lightweight formatting (Textile, Markdown) in database? I want to store comment formatting in some markup language in our DB. However, we want to allow multiple formatting ...

Vertical dividers on horizontal UL menu

I m trying to create a horizontal navigation bar (no dropdown, just a horizontal list), but I m having trouble finding the best way to add vertical dividers between the menu items. The actual HTML is ...

What are some alternatives to CSS to style your websites?

After asking this question, it appears that a lot of CSS hacks and tricks are needed to achieve something that simple. People have said that CSS is broken. So I wonder now, if not CSS, what are some ...

Is the concept of a link inseparable from its html markup?

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 ...

Building a markup parser in php

I have created a very simple markup parser in php. However, it currently uses str_replace to switch between markup and html. How can I make a "code" box of sorts (will eventually use GeSHI) that has ...

How do you put HTML or XML into a YAML?

I would like to store HTML snippets inside a YAML file. What is the best way to do that? Something like: myhtml: | <div> <a href="#">whatever</a> </div>

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

热门标签