Commit d2171d16 authored by Liang Ding's avatar Liang Ding

🗃 #12678

parent ebd1e57d
......@@ -28,7 +28,7 @@ import org.jsoup.safety.Whitelist;
* This class defines all article model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.0.1, Feb 28, 2019
* @version 1.4.0.0, Feb 28, 2019
* @since 0.3.1
*/
public final class Article {
......@@ -53,6 +53,11 @@ public final class Article {
*/
public static final String ARTICLE_ABSTRACT = "articleAbstract";
/**
* Key of abstract text.
*/
public static final String ARTICLE_ABSTRACT_TEXT = "articleAbstractText";
/**
* Key of content.
*/
......@@ -220,17 +225,32 @@ public final class Article {
}
/**
* Gets the abstract of the specified content.
* Gets the abstract plain text of the specified content.
*
* @param content the specified content
* @return the abstract
* @return the abstract plain text
*/
public static String getAbstractText(final String content) {
final String ret = Jsoup.clean(Markdowns.toHTML(content), Whitelist.none());
if (ret.length() > ARTICLE_ABSTRACT_LENGTH) {
return ret.substring(0, ARTICLE_ABSTRACT_LENGTH) + "....";
}
return ret;
}
/**
* Gets the abstract plain text of the specified article.
*
* @param article the specified article
* @return the abstract plain text
*/
public static String getAbstract(final String content) {
final String plainTextContent = Jsoup.clean(Markdowns.toHTML(content), Whitelist.none());
if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) {
return plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH) + "....";
public static String getAbstractText(final JSONObject article) {
String content = article.optString(Article.ARTICLE_ABSTRACT);
if (StringUtils.isBlank(content)) {
content = article.optString(Article.ARTICLE_CONTENT);
}
return plainTextContent;
return getAbstractText(content);
}
}
......@@ -445,15 +445,21 @@
},
{
"name": "articleAbstract",
"description": "文章摘要",
"description": "文章摘要 Markdown",
"type": "String",
"length": 2000
"length": 2048
},
{
"name": "articleAbstractText",
"description": "文章摘要纯文本",
"type": "String",
"length": 2048
},
{
"name": "articleTags",
"description": "文章标签,英文逗号分隔",
"type": "String",
"length": 2000
"length": 2048
},
{
"name": "articleAuthorId",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment