{{post.title}}
{{post.description}}
npm install markdown
var markdown = require( "markdown" ).markdown;
console.log( markdown.toHTML( "Hello *World*!" ) );
content:markdown.toHTML(row.content),
var restify = require('restify');
var _ = require('underscore')._;
var sqlite3 = require('sqlite3').verbose();
var markdown = require( "markdown" ).markdown;
var db = new sqlite3.Database('sqlite3.db');
var server = restify.createServer();
var content = new Array();
server.use(
function crossOrigin(req,res,next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
return next();
}
);
db.all("SELECT id,content,title,description,slug,created,updated,publish_date,keywords_string FROM blog_blogpost", function(err, rows) {
rows.forEach(function (row) {
content.push({
id:row.id,
slug:row.slug,
description:row.description,
title:row.title,
content:markdown.toHTML(row.content),
keywords:row.keywords_string,
created:row.created,
updated:row.updated,
publish_date:row.publish_date
});
});
function respond(req,res,next){
var data = content[req.params.name-1];
res.json(data, {'content-type': 'application/json; charset=utf-8'});
}
function all(req,res,next){
var data = {blogposts_sum:rows.length};
res.json(data, {'content-type': 'application/json; charset=utf-8'});
}
function respages(req,res,next){
var data = _.last(content,10);
data = data.reverse();
res.json(data, {'content-type': 'application/json; charset=utf-8'});
}
server.get ('/blog',all);
server.get ('/blog/page/:page',respages);
server.head ('/blog/page/:page',respages);
server.get ('/blog/:name',respond);
server.head ('/blog/:name',respond);
db.close();
});
server.listen(10086, function() {
console.log('%s listening at %s', server.name, server.url);
});
function Ctrl($scope, $sce) {
$scope.snippet =
'an html\n' +
'click here\n' +
'snippet
';
$scope.deliberatelyTrustDangerousSnippet = function() {
return $sce.trustAsHtml($scope.snippet);
};
}
##整合##
index.html部分
Phodal's New Homepage
{{post.title}}
{{post.description}}
app.js部分
var blogposts = angular.module('blogposts', []);
blogposts.controller('postlistCtrl', function($scope, $http, $sce) {
$http.get('http://0.0.0.0:10086/blog/page/1').success(function(data) {
$scope.posts = data;
});
$http.get('http://0.0.0.0:10086/blog/1').success(function(data) {
$scope.post1 = data;
console.log(data.content);
$scope.deliberatelyTrustDangerousSnippet = function() {
return $sce.trustAsHtml(data.content);
};
});
});