Skip to content

Commit

Permalink
decode article intro html
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucky-victory committed Apr 9, 2022
1 parent 5344d18 commit dfd605d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const getPublishedArticles=asyncHandler(async(req,res)=>{
articles=articles.map((article)=>{
article.title=decode(article.title);
article.content=decode(article.content);
article.intro=decode(article.intro);
article.author.bio=decode(article.author.bio);
article.tags=StringToArray(article.tags)
return article;
Expand Down
9 changes: 6 additions & 3 deletions controllers/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getArticlesByAuthor=asyncHandler(async(req,res)=>{
res.status(200).json({message:"No more Articles","articles":[]});
return
}
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.body,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=true AND u.username='${author}' ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.intro,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=true AND u.username='${author}' ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;

let articles=await Articles.query(articlesQuery);
// nest author info as author property
Expand All @@ -28,8 +28,11 @@ const getArticlesByAuthor=asyncHandler(async(req,res)=>{
// decode html entities
articles=articles.map((article)=>{
article.title=decode(article.title);
article.body=decode(article.body);
article.tags=StringToArray(article.tags)
article.content=decode(article.content);
article.author.bio=decode(article.author.bio);

article.tags=StringToArray(article.tags);
article.intro=decode(article.intro)
return article;
});
if(!articles.length){
Expand Down
9 changes: 6 additions & 3 deletions controllers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getCategories=asyncHandler(async(req,res)=>{
res.status(200).json({message:"No more Articles","articles":[]});
return
}
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.body,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=true ${!NullOrUndefined(category) ? ` AND category='${category}'`:''} ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.intro,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=true ${!NullOrUndefined(category) ? ` AND category='${category}'`:''} ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;

let articles=await Articles.query(articlesQuery);
// nest author info as author property
Expand All @@ -44,8 +44,11 @@ const getCategories=asyncHandler(async(req,res)=>{
// decode html entities
articles=articles.map((article)=>{
article.title=decode(article.title);
article.body=decode(article.body);
article.tags=StringToArray(article.tags)
article.content=decode(article.content);
article.tags=StringToArray(article.tags);
article.author.bio=decode(article.author.bio);

article.intro=decode(article.intro);
return article;
});
if(!articles.length){
Expand Down
7 changes: 5 additions & 2 deletions controllers/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getAllTags= asyncHandler(async(req,res)=>{
res.status(200).json({message:"No Articles","articles":[]});
return
}
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.body,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=false ${!NullOrUndefined(tag) ? ` AND tags IN("${tag.join('","')}")`:''} ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;
const articlesQuery=`SELECT a.id,a.publishedAt,a.title,a.authorId,a.intro,a.views,a.heroImage,a.slug,a.tags,a.category,a.content,a.readTime,a.modifiedAt,u.fullname as _fullname,u.id as _id,u.twitter as _twitter,u.linkedIn as _linkedin,u.bio as _bio,u.username as _username,u.profileImage as _profileImage FROM ArticlesSchema.Articles as a INNER JOIN ArticlesSchema.Authors as u ON a.authorId=u.id WHERE a.published=false ${!NullOrUndefined(tag) ? ` AND tags IN("${tag.join('","')}")`:''} ORDER BY a.${orderBy} ${order} LIMIT ${limit} OFFSET ${offset} `;

let articles=await Articles.query(articlesQuery);

Expand All @@ -53,7 +53,10 @@ articles=nester(articles,["_fullname","_id","_bio","_twitter","_linkedin","_user
// decode html entities
articles=articles.map((article)=>{
article.title=decode(article.title);
article.body=decode(article.body);
article.content=decode(article.content);
article.intro=decode(article.intro);
article.author.bio=decode(article.author.bio);

article.tags=StringToArray(article.tags)
return article;
});
Expand Down

0 comments on commit dfd605d

Please sign in to comment.