Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
郝肖肖
7 years ago
Commit
d05e17900290589f436d1c84b9c3f11d8426968b
1 parent
adacd812
'news-xss'
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
3 deletions
.gitignore
apps/news/controllers/index.js
apps/news/models/news-service.js
apps/news/models/utils.js
package.json
public/scss/news/_detail.css
.gitignore
View file @
d05e179
...
...
@@ -150,3 +150,4 @@ library
### foreman ###
Procfile
.env
.package-lock
...
...
apps/news/controllers/index.js
View file @
d05e179
...
...
@@ -14,6 +14,10 @@ exports.index = (req, res, next) => {
let
channel
=
req
.
yoho
.
channel
;
req
.
ctx
(
newsService
).
getIndexList
(
channel
,
req
.
query
).
then
(
result
=>
{
if
(
result
.
msgs
.
length
<=
0
)
{
res
.
set
(
'Cache-Control'
,
'no-cache'
);
}
return
res
.
render
(
'news-index'
,
Object
.
assign
({
title
:
'新闻 | '
+
(
res
.
locals
.
title
||
''
),
module
:
'news'
,
...
...
apps/news/models/news-service.js
View file @
d05e179
...
...
@@ -4,7 +4,9 @@ const _ = require('lodash');
const
helpers
=
global
.
yoho
.
helpers
;
const
headerModel
=
require
(
'../../../doraemon/models/header'
);
const
NewsAPi
=
require
(
'./news-api'
);
const
utils
=
require
(
'./utils'
);
const
moment
=
require
(
'moment'
);
const
xss
=
require
(
'xss'
);
const
searchHandler
=
require
(
'../../product/models/search-handler'
);
console
.
log
(
global
.
utils
);
...
...
@@ -121,6 +123,7 @@ module.exports = class extends global.yoho.BaseModel {
let
newsAPi
=
new
NewsAPi
(
this
.
ctx
);
let
params
=
{
type
:
'wechat'
,
atype
:
param
.
atype
||
'yohogroup'
,
limit
:
20
,
page
:
param
.
page
||
1
};
...
...
@@ -132,7 +135,7 @@ module.exports = class extends global.yoho.BaseModel {
content_code
:
ADS_CODE
[
channel
]
||
ADS_CODE
.
boys
,
isAdDegrade
:
_
.
get
(
this
.
ctx
,
'req.app.locals.pc.guang.removeAd'
,
false
)
}),
newsAPi
.
getPolymerizationList
(
params
),
newsAPi
.
getPolymerizationList
(
Object
.
assign
({},
params
,
{
id
:
param
.
atype
||
'yohogroup'
})
),
];
return
Promise
.
all
(
apiMethod
).
then
(
result
=>
{
...
...
@@ -163,8 +166,13 @@ module.exports = class extends global.yoho.BaseModel {
title
:
contents
.
title
,
time
:
contents
.
update_time
&&
moment
(
contents
.
update_time
*
1000
).
format
(
'YYYY年MM月DD HH:mm'
),
};
let
content
=
utils
.
filterPhtml
(
contents
.
content
,
[
'阅读原文'
,
'点击这里'
,
'点这里'
]);
return
{
header
:
header
,
content
:
contents
.
content
};
return
{
header
:
header
,
content
:
xss
(
utils
.
filterAhtml
(
content
))
};
}
detail
(
channel
,
param
)
{
...
...
apps/news/models/utils.js
0 → 100644
View file @
d05e179
'use strict'
;
const
_
=
require
(
'lodash'
);
const
cheerio
=
require
(
'cheerio'
);
const
util
=
{
// 过滤指定字符的p标签
filterPhtml
:
(
html
,
filters
)
=>
{
if
(
!
html
)
{
return
html
;
}
let
$
=
cheerio
.
load
(
html
,
{
decodeEntities
:
false
});
_
.
each
(
$
(
'p'
),
(
item
)
=>
{
let
ele
=
$
(
item
);
let
phtml
=
ele
.
html
();
_
.
each
(
filters
,
ft
=>
{
if
(
phtml
.
indexOf
(
ft
)
>=
0
)
{
ele
.
remove
();
}
});
});
return
$
.
html
();
},
// 过滤 a标签连接
filterAhtml
:
(
html
)
=>
{
if
(
!
html
)
{
return
html
;
}
let
$
=
cheerio
.
load
(
html
,
{
decodeEntities
:
false
});
$
(
'a'
).
attr
(
'href'
,
'javascript:void(0);'
).
css
({
cursor
:
'text'
});
return
$
.
html
();
}
};
module
.
exports
=
util
;
...
...
package.json
View file @
d05e179
...
...
@@ -54,6 +54,7 @@
"sitemap"
:
"^1.12.1"
,
"urlencode"
:
"^1.1.0"
,
"uuid"
:
"^2.0.2"
,
"xss"
:
"^0.3.4"
,
"yoho-express-session"
:
"^2.0.0"
,
"yoho-node-lib"
:
"=0.5.4"
,
"yoho-zookeeper"
:
"^1.0.8"
...
...
public/scss/news/_detail.css
View file @
d05e179
...
...
@@ -53,7 +53,7 @@
.detail-title
{
font-size
:
28px
;
line-height
:
45
px
;
line-height
:
50
px
;
border-bottom
:
1px
dotted
#c1c1c1
;
word-wrap
:
break-word
;
}
...
...
Please
register
or
login
to post a comment