Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

article

  • Loading branch information...
commit f16cd519c9a8ad0cb356164fe2808c1275801b6d 1 parent 7e7bb4e
julius xue authored
View
2  controller/app.js
@@ -24,7 +24,7 @@ app.post('/chat',site.loginAction);
app.post('/img',site.uploadImg);
app.get('/backend/:op',site.backendDispatcher);
app.post('/backend/:op',site.backendDispatcher);
-app.get('/articles',site.listArticle);
+app.get('/articles/:id?',site.listArticle);
app.listen(8081);
View
4 controller/common.js
@@ -1,5 +1,5 @@
-exports.dateFormat = function(fmt) {
- var now = new Date();
+exports.dateFormat = function(fmt,timeline) {
+ var now = timeline? new Date(timeline) : new Date();
var o = {
"M+" : now.getMonth()+1, //月份
"d+" : now.getDate(), //日
View
45 controller/site.js
@@ -1,6 +1,7 @@
var sqlite3 = require('sqlite3').verbose();
var databasename = 'database.db';
var fs = require('fs');
+var common = require('./common.js');
exports.index = function(req,res){
var tplParam = {htmltitle: 'layout title'};
@@ -72,19 +73,37 @@ exports.listUser = function(req,res){
exports.listArticle = function(req,res){
var db = new sqlite3.Database(databasename);
- var list = new Array();
- var tmp = '';
- db.serialize(function() {
- db.each("SELECT rowid AS id, title, body, author, dateline FROM article", function(err, row) {
- if(row){
- tmp = row.id + ": " + unescape(row.title) + " - " + unescape(row.body) + " - " + unescape(row.author) + " - " + new Date(row.dateline);
- list.push(tmp);
- }
- },
- function(){
- res.render('article_list',{articles: list, htmltitle: 'articlelist'});
- });
- });
+ if(req.params.id){
+ db.serialize(function() {
+ var stmt = db.prepare("SELECT rowid as id, title, body, author, dateline FROM article WHERE rowid=?");
+ stmt.get(req.params.id,function(err, row){
+ if(row){
+ row.body = unescape(row.body);
+ row.title = unescape(row.title);
+ row.author = unescape(row.author);
+ row.dateline = common.dateFormat("yyyy-MM-dd EE hh:mm:ss",row.dateline);
+ res.render('article',{htmltitle: 'chat', article: row});
+ }else{
+ res.send('no article');
+ }
+ });
+ stmt.finalize();
+ });
+ }else{
+ var list = new Array();
+ var tmp = '';
+ db.serialize(function() {
+ db.each("SELECT rowid AS id, title, body, author, dateline FROM article", function(err, row) {
+ if(row){
+ tmp = row.id + ": " + unescape(row.title) + " - " + unescape(row.body) + " - " + unescape(row.author) + " - " + new Date(row.dateline);
+ list.push(tmp);
+ }
+ },
+ function(){
+ res.render('article_list',{articles: list, htmltitle: 'articlelist'});
+ });
+ });
+ }
db.close();
}
View
3  log/chat_history_log_2012-06-22.log
@@ -0,0 +1,3 @@
+2012-06-22 周五 11:39:34###new###das######
+2012-06-22 周五 11:39:35###new###dasdsa######
+2012-06-22 周五 11:39:37###new###dasdsadsa######
View
3  view/article.ejs
@@ -0,0 +1,3 @@
+<h1><%= article.title %></h1>
+<p><%= article.author %> - <%= article.dateline %></p>
+<p><%- article.body %></p>
Please sign in to comment.
Something went wrong with that request. Please try again.