Yoji SHIDARA
null+****@clear*****
Wed Aug 15 17:42:26 JST 2012
Yoji SHIDARA 2012-08-15 17:42:26 +0900 (Wed, 15 Aug 2012) New Revision: 58c78f9806741da2b8025b9997e8ec7cfb781960 https://github.com/nroonga/norema/commit/58c78f9806741da2b8025b9997e8ec7cfb781960 Log: Link to all.html on node.js website Some entries do not have the corresponding anchor. In order to fix this, conversion script should be more sophisticated. Modified files: lib/server.js tools/convert.js views/search.jade Modified: lib/server.js (+9 -0) =================================================================== --- lib/server.js 2012-08-15 17:05:15 +0900 (2e8fc1b) +++ lib/server.js 2012-08-15 17:42:26 +0900 (fbf2b80) @@ -56,6 +56,14 @@ function search(query, callback) { request.end(); } +function titleToId(title) { + return title + .toString() + .toLowerCase() + .replace(/[^a-z0-9]+/g, '_') + .replace(/^_|_$/g, ''); +} + // routings app.get('/', function(request, response){ return response.render('index.jade', {query: ''}); @@ -71,6 +79,7 @@ app.get('/search', function(request, response, next) { } var locals = { querystring: querystring, + titleToId: titleToId, query: query, records: results.hits.hit, num_found: results.hits.found, Modified: tools/convert.js (+11 -1) =================================================================== --- tools/convert.js 2012-08-15 17:05:15 +0900 (0c2256a) +++ tools/convert.js 2012-08-15 17:42:26 +0900 (da7f286) @@ -24,6 +24,13 @@ function htmlToText(html, callback) { }); } +function titleToId(title) { + return title + .toLowerCase() + .replace(/[^a-z0-9]+/g, '_') + .replace(/^_|_$/g, ''); +} + function parse(doc, context) { var item = {}; @@ -39,6 +46,8 @@ function parse(doc, context) { if (doc.desc) { item.desc = doc.desc; item.title = context.title; + item.id = titleToId(context.title); + console.log([item.id, item.title]); item.path = context.path.map(function(item) { return item.title; }).filter(function(title) { @@ -49,6 +58,7 @@ function parse(doc, context) { context.path.push(item); for (var type in doc) { + console.log("TYPE", type); if (doc[type] instanceof Array) { doc[type].forEach(function(subdoc) { parse(subdoc, context); @@ -64,7 +74,7 @@ function toSdf(records) { var version = (new Date()).getTime(); return records.map(function(record, index) { - console.log(index, record.path, record.title); + //console.log(index, record.path, record.title); return { type: 'add', id: 'doc_' + index, Modified: views/search.jade (+2 -1) =================================================================== --- views/search.jade 2012-08-15 17:05:15 +0900 (5c83ca8) +++ views/search.jade 2012-08-15 17:42:26 +0900 (8a2e2fe) @@ -19,7 +19,8 @@ block content if records.length > 0 each record, index in records .record - h2 #{record.data.title} + h2 + a(href="http://nodejs.org/docs/latest/api/all.html#all_"+titleToId(record.data.title), target="_blank")= record.data.title p.path each title, pathIndex in record.data.path span -------------- next part -------------- HTML����������������������������...Download