How should I be storing comments?
A user enters a comment, let's say:
Yes, great blog post. See http://www.link.com for more information!
We will assume that the link is good quality and relevant and not spammy in anyway.
Now, we want to automatically convert URL's to this format with regexp, formatting the link to be clickable and SEO'd:
Yes, great blog post. See <a h开发者_运维技巧ref="http://www.link.com" rel="nofollow" class="blog-comment-link">http://www.link.com</a> for more information!
Should we be formatting the link before it is inserted into the database and saved permamently, or should the formatting be done client side with Jquery making it easier to make site wide changes?
I would save it in a slightly different form. Something like:
Yes, great blog post. See #URL{http://www.link.com} for more information!
Basically, you want to do the 'looking for URL' code only once. On the other hand, you want to be able to change markup when you change site design and so on. BTW, I think this is similar to how wiki servers save their pages.
I'd plump for the latter: you could end up adding other code to the tag, for example tooltips or javascript code. Storing markup in a DB is probably a no-no.
On the other hand... if you use a posh edit control such as the html edit box that comes with the ajax control toolkit, then you'd have the code on the DB with very little changes required (just the rel attribute to add).
精彩评论