Permalink
Browse files

Added Chris Messina’s Twitter-style hashtags.

  • Loading branch information...
1 parent 3903749 commit ecbd9f34b234822b418285e614679e9eeffd6037 @kragen committed May 14, 2011
Showing with 43 additions and 7 deletions.
  1. +2 −2 README.md
  2. +41 −5 blog.html
View
@@ -51,6 +51,8 @@ DONE
- a “public” checkbox to allow private annotations
- giving blog view a stylesheet to make it look good
- dismissing annotation popup
+- tagging: Twitter-like, #hashtags in the blog view are links to
+ filtered views that show only things tagged with that hashtag.
BUGS
----
@@ -158,8 +160,6 @@ TODO (possibly)
- publishing your bookmarks as a blog on the web
- saving previous versions of annotations
- syncing across multiple browsers
-- tagging: Twitter-like, #hashtags in the blog view will be links to
- filtered views that show only things tagged with that hashtag.
- saving highlighted quotations from pages
- automatically parsing dates from pages and displaying bookmarks in a calendar view
- Lotus-Agenda-like auto-tagging based on user-specified keywords
View
@@ -48,21 +48,54 @@
<script src="mustache/mustache.js"></script>
<script src="db.js"></script>
<script>
- $(renderBlog);
+ $(renderPage);
var template =
'{{#sections}}' +
'<h2>{{date}}</h2>' +
' <ul>' +
' {{#bookmarks}}' +
' <li><a href="{{url}}">{{title}}</a> ' +
- ' <span class="annotation">{{annotation}}</span>' +
+ ' <span class="annotation">{{{annotation}}}</span>' +
' </li>' +
' {{/bookmarks}}' +
' </ul>' +
'{{/sections}}' ;
- function renderBlog() {
+ function tags(text) {
+ return text.match(/#\w+/g) || [];
+ }
+
+ function contains(item, list) {
+ for (var ii = 0; ii < list.length; ii++) {
+ if (item === list[ii]) return true;
+ }
+ return false;
+ }
+
+ function taggify(text) {
+ return text
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/(#\w+)/g, function(tag) {
+ var param = encodeURIComponent(tag);
+ return '<a href="?'+param+'">'+tag+'</a>';
+ })
+ ;
+ }
+
+ function renderPage() {
+ if (location.search) {
+ var tag = decodeURIComponent(location.search.substr(1));
+ $('.forwhat').text(' for '+tag);
+ document.title = $('h1').text();
+ renderBlog(tag);
+ } else {
+ renderBlog(null);
+ }
+ }
+
+ function renderBlog(tag) {
var start = new Date();
sql( 'select *, date(timestamp) as date from annotations ' +
'order by timestamp desc'
@@ -73,6 +106,9 @@
for (var ii = 0; ii < results.rows.length; ii++) {
var row = results.rows.item(ii);
+ if (tag && !contains(tag, tags(row.annotation))) {
+ continue;
+ }
if (row.date !== section.date) {
section = { date: row.date, bookmarks: [] };
@@ -81,7 +117,7 @@
section.bookmarks.push({ url: row.url
, title: row.title || '<link>'
- , annotation: row.annotation
+ , annotation: taggify(row.annotation)
});
}
@@ -103,6 +139,6 @@
</script>
</head><body>
- <h1>Your Yamemex Annotations</h1>
+ <h1>Your Yamemex Annotations<span class="forwhat"></span></h1>
<div id="entries"></div>
</body></html>

0 comments on commit ecbd9f3

Please sign in to comment.