链接的概念与其 html 标记密不可分吗?

发布于 2024-08-13 03:00:49 字数 1026 浏览 9 评论 0 原文

我正在寻找一种管理文章内链接的策略。文章正文保存在数据库中,并在页面组装期间提取。为了轻松定义和管理链接,应该将哪些内容保存在数据库中?

一些纯粹主义者认为标记永远不应该存储在数据库中。有些人认为适度即可。但对我来说,链接的概念几乎与其 html 标记密不可分。

有没有比简单地嵌入“锚文本”更好、更简洁的方式来表示文章(数据库中)中的链接?

我提出的一个想法是嵌入足够的标记来从语义上描述感兴趣的区域,并在另一个表中将这些概念映射到实际的 URL。所有遇到的特定概念都会被链接包裹起来。

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

然后,表格可以将文章的 URL 和“semantic-web”的键类关联到类似 的 URL 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>

我喜欢这种方法的一点是我的所有 URL 都位于数据库中的一个位置。从技术上讲,我可以更改或删除链接,而无需触及文章正文。我有很好的 CSS 类名。

我不喜欢维护另一个表,以及渲染时间的另一个步骤/阶段。它可能会减慢响应时间。

还有其他策略可以提供卓越的链接管理吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太傻旳人生 2024-08-20 03:00:49

您可能需要查看模板(例如 PHP 的 Smarty)。

我同意标记通常不应该保存在数据库中。

但是,您也可以考虑实现“指针”概念,在每个链接处,您中断页面的存储,在表中添加指向链接的指针,然后在链接表中添加指向下一个内容段的指针页面。 (我不知道这有多复杂 - 只是一个想法。)

或者看看各种 CMS 工具如何处理这个想法。有些只是将数据库中的所有内容作为一大块文本,而另一些则依赖模板,还有一些可能完全做其他事情(例如面向对象的环境,例如 克隆)。

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

初心未许 2024-08-20 03:00:49

我见过一些这样做的尝试。

一种方法是通过 URL 重定向。您可以在服务器上实现一个逻辑组件,该组件将解释 URL 所请求的内容,而不是内容的路径。

另一种尝试是链接最初设置为参考值[可以在数据库中查找],并在运行时/生成时请求。

无论如何,您必须使用某种标识符来引用您希望链接到的材料。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文