Navigation Menu

Skip to content

Commit

Permalink
Link to all.html on node.js website
Browse files Browse the repository at this point in the history
Some entries do not have the corresponding anchor.
In order to fix this, conversion script should be more sophisticated.
  • Loading branch information
darashi committed Aug 15, 2012
1 parent ef34b23 commit 58c78f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/server.js
Expand Up @@ -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: ''});
Expand All @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion tools/convert.js
Expand Up @@ -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 = {};

Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion views/search.jade
Expand Up @@ -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
Expand Down

0 comments on commit 58c78f9

Please sign in to comment.