apostrophe-snippets
Advanced tools
Comparing version 0.0.10 to 0.0.11
46
index.js
@@ -97,2 +97,3 @@ var async = require('async'); | ||
self._app = options.app; | ||
self._searchable = options.searchable || true; | ||
self._options = options; | ||
@@ -987,2 +988,14 @@ self._dirs = (options.dirs || []).concat([ __dirname ]); | ||
// The default properties for snippets are already covered by the | ||
// default properties for pages in general. Extend this to add more | ||
// search texts representing metadata relating to | ||
// this type of snippet. Always call the superclass version. Example: | ||
// texts.push({ weight: 20, text: snippet.address }) | ||
// | ||
// The default search engine is very simplistic. Searches that match | ||
// something weighted 11 or higher appear before everything else. | ||
self.addSearchTexts = function(snippet, texts) { | ||
}; | ||
// Add a listener so we can contribute our own metadata to the set of lines used | ||
@@ -999,2 +1012,35 @@ // for the diffs between versions. Pass an inline function so that self.addDiffLines | ||
self._apos.addListener('index', function(snippet, lines) { | ||
if (snippet.type === self._instance) { | ||
self.addSearchTexts(snippet, lines); | ||
} | ||
}); | ||
self._apos.addListener('searchResult', function(req, res, page, context) { | ||
// Not all types are searchable on all sites, snippets usually | ||
// have this shut off because they have no permalinks | ||
if (!self._searchable) { | ||
return; | ||
} | ||
console.log('searchable for ' + self._instance); | ||
// Don't mess with a result another listener already accepted | ||
if (context.accepted) { | ||
return; | ||
} | ||
if (self._instance === page.type) { | ||
// Set the accepted flag so the pages module doesn't 404 the search result. | ||
// Now we can asynchronously work on it | ||
context.accepted = true; | ||
// The result belongs to us now, let's figure out what to do with it. | ||
return self.findBestPage(req, page, function(err, bestPage) { | ||
if (!bestPage) { | ||
res.statusCode = 404; | ||
return res.send('Not Found'); | ||
} | ||
var url = self.permalink(page, bestPage); | ||
return res.redirect(url); | ||
}); | ||
} | ||
}); | ||
// Add the .url property to snippets so they can be clicked through | ||
@@ -1001,0 +1047,0 @@ self.addUrls = function(req, snippets, callback) { |
{ | ||
"name": "apostrophe-snippets", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Reusable content snippets for the Apostrophe content management system. The blog and events modules are built on this foundation, which is also useful in and of itself.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
74469
1574
0