use of run.halo.app.model.params.PostParam in project halo by ruibaby.
the class PostServiceImpl method importMarkdown.
@Override
public PostDetailVO importMarkdown(String markdown, String filename) {
Assert.notNull(markdown, "Markdown document must not be null");
// Gets frontMatter
Map<String, List<String>> frontMatter = MarkdownUtils.getFrontMatter(markdown);
// remove frontMatter
markdown = MarkdownUtils.removeFrontMatter(markdown);
PostParam post = new PostParam();
post.setStatus(null);
List<String> elementValue;
Set<Integer> tagIds = new HashSet<>();
Set<Integer> categoryIds = new HashSet<>();
if (frontMatter.size() > 0) {
for (String key : frontMatter.keySet()) {
elementValue = frontMatter.get(key);
for (String ele : elementValue) {
ele = HaloUtils.strip(ele, "[", "]");
ele = StringUtils.strip(ele, "\"");
ele = StringUtils.strip(ele, "\'");
if ("".equals(ele)) {
continue;
}
switch(key) {
case "title":
post.setTitle(ele);
break;
case "date":
post.setCreateTime(DateUtils.parseDate(ele));
break;
case "permalink":
post.setSlug(ele);
break;
case "thumbnail":
post.setThumbnail(ele);
break;
case "status":
post.setStatus(PostStatus.valueOf(ele));
break;
case "comments":
post.setDisallowComment(Boolean.parseBoolean(ele));
break;
case "tags":
Tag tag;
for (String tagName : ele.split(",")) {
tagName = tagName.trim();
tagName = StringUtils.strip(tagName, "\"");
tagName = StringUtils.strip(tagName, "\'");
tag = tagService.getByName(tagName);
String slug = SlugUtils.slug(tagName);
if (null == tag) {
tag = tagService.getBySlug(slug);
}
if (null == tag) {
tag = new Tag();
tag.setName(tagName);
tag.setSlug(slug);
tag = tagService.create(tag);
}
tagIds.add(tag.getId());
}
break;
case "categories":
Integer lastCategoryId = null;
for (String categoryName : ele.split(",")) {
categoryName = categoryName.trim();
categoryName = StringUtils.strip(categoryName, "\"");
categoryName = StringUtils.strip(categoryName, "\'");
Category category = categoryService.getByName(categoryName);
if (null == category) {
category = new Category();
category.setName(categoryName);
category.setSlug(SlugUtils.slug(categoryName));
category.setDescription(categoryName);
if (lastCategoryId != null) {
category.setParentId(lastCategoryId);
}
category = categoryService.create(category);
}
lastCategoryId = category.getId();
categoryIds.add(lastCategoryId);
}
break;
default:
break;
}
}
}
}
if (null == post.getStatus()) {
post.setStatus(PostStatus.PUBLISHED);
}
if (StringUtils.isEmpty(post.getTitle())) {
post.setTitle(filename);
}
if (StringUtils.isEmpty(post.getSlug())) {
post.setSlug(SlugUtils.slug(post.getTitle()));
}
post.setOriginalContent(markdown);
return createBy(post.convertTo(), tagIds, categoryIds, false);
}
use of run.halo.app.model.params.PostParam in project halo by ruibaby.
the class InstallController method createDefaultPostIfAbsent.
@Nullable
private PostDetailVO createDefaultPostIfAbsent(@Nullable Category category) {
long publishedCount = postService.countByStatus(PostStatus.PUBLISHED);
if (publishedCount > 0) {
return null;
}
PostParam postParam = new PostParam();
postParam.setSlug("hello-halo");
postParam.setTitle("Hello Halo");
postParam.setStatus(PostStatus.PUBLISHED);
postParam.setOriginalContent("## Hello Halo\n" + "\n" + "如果你看到了这一篇文章,那么证明你已经安装成功了,感谢使用 [Halo](https://halo.run) 进行创作,希望能够使用愉快。\n" + "\n" + "## 相关链接\n" + "\n" + "- 官网:[https://halo.run](https://halo.run)\n" + "- 文档:[https://docs.halo.run](https://docs.halo.run)\n" + "- 社区:[https://bbs.halo.run](https://bbs.halo.run)\n" + "- 主题仓库:[https://halo.run/themes.html](https://halo.run/themes.html)\n" + "- 开源地址:[https://github.com/halo-dev/halo](https://github.com/halo-dev/halo)\n" + "\n" + "在使用过程中,有任何问题都可以通过以上链接找寻答案,或者联系我们。\n" + "\n" + "> 这是一篇自动生成的文章,请删除这篇文章之后开始你的创作吧!\n" + "\n");
Set<Integer> categoryIds = new HashSet<>();
if (category != null) {
categoryIds.add(category.getId());
postParam.setCategoryIds(categoryIds);
}
return postService.createBy(postParam.convertTo(), Collections.emptySet(), categoryIds, false);
}
use of run.halo.app.model.params.PostParam in project halo by halo-dev.
the class PostServiceImpl method importMarkdown.
@Override
public PostDetailVO importMarkdown(String markdown, String filename) {
Assert.notNull(markdown, "Markdown document must not be null");
// Gets frontMatter
Map<String, List<String>> frontMatter = MarkdownUtils.getFrontMatter(markdown);
// remove frontMatter
markdown = MarkdownUtils.removeFrontMatter(markdown);
PostParam post = new PostParam();
post.setStatus(null);
List<String> elementValue;
Set<Integer> tagIds = new HashSet<>();
Set<Integer> categoryIds = new HashSet<>();
if (frontMatter.size() > 0) {
for (String key : frontMatter.keySet()) {
elementValue = frontMatter.get(key);
for (String ele : elementValue) {
ele = HaloUtils.strip(ele, "[", "]");
ele = StringUtils.strip(ele, "\"");
ele = StringUtils.strip(ele, "\'");
if ("".equals(ele)) {
continue;
}
switch(key) {
case "title":
post.setTitle(ele);
break;
case "date":
post.setCreateTime(DateUtils.parseDate(ele));
break;
case "permalink":
post.setSlug(ele);
break;
case "thumbnail":
post.setThumbnail(ele);
break;
case "status":
post.setStatus(PostStatus.valueOf(ele));
break;
case "comments":
post.setDisallowComment(Boolean.parseBoolean(ele));
break;
case "tags":
Tag tag;
for (String tagName : ele.split(",")) {
tagName = tagName.trim();
tagName = StringUtils.strip(tagName, "\"");
tagName = StringUtils.strip(tagName, "\'");
tag = tagService.getByName(tagName);
String slug = SlugUtils.slug(tagName);
if (null == tag) {
tag = tagService.getBySlug(slug);
}
if (null == tag) {
tag = new Tag();
tag.setName(tagName);
tag.setSlug(slug);
tag = tagService.create(tag);
}
tagIds.add(tag.getId());
}
break;
case "categories":
Integer lastCategoryId = null;
for (String categoryName : ele.split(",")) {
categoryName = categoryName.trim();
categoryName = StringUtils.strip(categoryName, "\"");
categoryName = StringUtils.strip(categoryName, "\'");
Category category = categoryService.getByName(categoryName);
if (null == category) {
category = new Category();
category.setName(categoryName);
category.setSlug(SlugUtils.slug(categoryName));
category.setDescription(categoryName);
if (lastCategoryId != null) {
category.setParentId(lastCategoryId);
}
category = categoryService.create(category);
}
lastCategoryId = category.getId();
categoryIds.add(lastCategoryId);
}
break;
default:
break;
}
}
}
}
if (null == post.getStatus()) {
post.setStatus(PostStatus.PUBLISHED);
}
if (StringUtils.isEmpty(post.getTitle())) {
post.setTitle(filename);
}
if (StringUtils.isEmpty(post.getSlug())) {
post.setSlug(SlugUtils.slug(post.getTitle()));
}
post.setOriginalContent(markdown);
return createBy(post.convertTo(), tagIds, categoryIds, false);
}
use of run.halo.app.model.params.PostParam in project halo-plugin-experimental by guqing.
the class PostServiceImpl method importMarkdown.
@Override
public PostDetailVO importMarkdown(String markdown, String filename) {
Assert.notNull(markdown, "Markdown document must not be null");
// Gets frontMatter
Map<String, List<String>> frontMatter = MarkdownUtils.getFrontMatter(markdown);
// remove frontMatter
markdown = MarkdownUtils.removeFrontMatter(markdown);
PostParam post = new PostParam();
post.setStatus(null);
List<String> elementValue;
Set<Integer> tagIds = new HashSet<>();
Set<Integer> categoryIds = new HashSet<>();
if (frontMatter.size() > 0) {
for (String key : frontMatter.keySet()) {
elementValue = frontMatter.get(key);
for (String ele : elementValue) {
ele = HaloUtils.strip(ele, "[", "]");
ele = StringUtils.strip(ele, "\"");
ele = StringUtils.strip(ele, "\'");
if ("".equals(ele)) {
continue;
}
switch(key) {
case "title":
post.setTitle(ele);
break;
case "date":
post.setCreateTime(DateUtils.parseDate(ele));
break;
case "permalink":
post.setSlug(ele);
break;
case "thumbnail":
post.setThumbnail(ele);
break;
case "status":
post.setStatus(PostStatus.valueOf(ele));
break;
case "comments":
post.setDisallowComment(Boolean.parseBoolean(ele));
break;
case "tags":
Tag tag;
for (String tagName : ele.split(",")) {
tagName = tagName.trim();
tagName = StringUtils.strip(tagName, "\"");
tagName = StringUtils.strip(tagName, "\'");
tag = tagService.getByName(tagName);
String slug = SlugUtils.slug(tagName);
if (null == tag) {
tag = tagService.getBySlug(slug);
}
if (null == tag) {
tag = new Tag();
tag.setName(tagName);
tag.setSlug(slug);
tag = tagService.create(tag);
}
tagIds.add(tag.getId());
}
break;
case "categories":
Integer lastCategoryId = null;
for (String categoryName : ele.split(",")) {
categoryName = categoryName.trim();
categoryName = StringUtils.strip(categoryName, "\"");
categoryName = StringUtils.strip(categoryName, "\'");
Category category = categoryService.getByName(categoryName);
if (null == category) {
category = new Category();
category.setName(categoryName);
category.setSlug(SlugUtils.slug(categoryName));
category.setDescription(categoryName);
if (lastCategoryId != null) {
category.setParentId(lastCategoryId);
}
category = categoryService.create(category);
}
lastCategoryId = category.getId();
categoryIds.add(lastCategoryId);
}
break;
default:
break;
}
}
}
}
if (null == post.getStatus()) {
post.setStatus(PostStatus.PUBLISHED);
}
if (StringUtils.isEmpty(post.getTitle())) {
post.setTitle(filename);
}
if (StringUtils.isEmpty(post.getSlug())) {
post.setSlug(SlugUtils.slug(post.getTitle()));
}
post.setOriginalContent(markdown);
return createBy(post.convertTo(), tagIds, categoryIds, false);
}
use of run.halo.app.model.params.PostParam in project halo by halo-dev.
the class InstallController method createDefaultPostIfAbsent.
@Nullable
private PostDetailVO createDefaultPostIfAbsent(@Nullable Category category) {
long publishedCount = postService.countByStatus(PostStatus.PUBLISHED);
if (publishedCount > 0) {
return null;
}
PostParam postParam = new PostParam();
postParam.setSlug("hello-halo");
postParam.setTitle("Hello Halo");
postParam.setStatus(PostStatus.PUBLISHED);
postParam.setOriginalContent("## Hello Halo\n" + "\n" + "如果你看到了这一篇文章,那么证明你已经安装成功了,感谢使用 [Halo](https://halo.run) 进行创作,希望能够使用愉快。\n" + "\n" + "## 相关链接\n" + "\n" + "- 官网:[https://halo.run](https://halo.run)\n" + "- 文档:[https://docs.halo.run](https://docs.halo.run)\n" + "- 社区:[https://bbs.halo.run](https://bbs.halo.run)\n" + "- 主题仓库:[https://halo.run/themes.html](https://halo.run/themes.html)\n" + "- 开源地址:[https://github.com/halo-dev/halo](https://github.com/halo-dev/halo)\n" + "\n" + "在使用过程中,有任何问题都可以通过以上链接找寻答案,或者联系我们。\n" + "\n" + "> 这是一篇自动生成的文章,请删除这篇文章之后开始你的创作吧!\n" + "\n");
Set<Integer> categoryIds = new HashSet<>();
if (category != null) {
categoryIds.add(category.getId());
postParam.setCategoryIds(categoryIds);
}
return postService.createBy(postParam.convertTo(), Collections.emptySet(), categoryIds, false);
}
Aggregations