diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/core/config/SeoConfig.java b/novel-front/src/main/java/xyz/zinglizingli/books/core/config/SeoConfig.java new file mode 100644 index 0000000..764c450 --- /dev/null +++ b/novel-front/src/main/java/xyz/zinglizingli/books/core/config/SeoConfig.java @@ -0,0 +1,19 @@ +package xyz.zinglizingli.books.core.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.Map; + + +/** + * @author 11797 + */ +@Data +@Component +@ConfigurationProperties(prefix="website") +public class SeoConfig { + + private Map page; +} diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/core/listener/StartListener.java b/novel-front/src/main/java/xyz/zinglizingli/books/core/listener/StartListener.java index def06c8..f661b68 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/core/listener/StartListener.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/core/listener/StartListener.java @@ -3,9 +3,11 @@ package xyz.zinglizingli.books.core.listener; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; +import xyz.zinglizingli.books.core.config.SeoConfig; import xyz.zinglizingli.books.core.crawl.BaseCrawlSource; import xyz.zinglizingli.books.core.utils.Constants; +import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; @@ -23,13 +25,22 @@ public class StartListener implements ServletContextListener { @Value("${crawl.book.new.enabled}") private String crawlEnable; - @Value("${website.name}") - private String webSiteName; + @Value("${website.page.index.title}") + private String title; + + @Value("${website.domain}") + private String webSiteDomain; + + private final SeoConfig seoConfig; + @Override public void contextInitialized(ServletContextEvent servletContextEvent) { - servletContextEvent.getServletContext().setAttribute("websiteName",webSiteName); + ServletContext application = servletContextEvent.getServletContext(); + + application.setAttribute("webSiteDomain",webSiteDomain); + application.setAttribute(Constants.SEO_CONFIG_KEY,seoConfig); if (!Constants.ENABLE_NEW_BOOK.equals(crawlEnable.trim())) { log.info("程序启动"); new Thread(() -> { diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/core/utils/Constants.java b/novel-front/src/main/java/xyz/zinglizingli/books/core/utils/Constants.java index 5069686..3784fdd 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/core/utils/Constants.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/core/utils/Constants.java @@ -100,4 +100,9 @@ public class Constants { * 是否开启抓取新书 * */ public static final String ENABLE_NEW_BOOK = "true"; + + /** + * SEO配置保存的key + * */ + public static final String SEO_CONFIG_KEY = "seoConfig"; } diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/web/BookController.java b/novel-front/src/main/java/xyz/zinglizingli/books/web/BookController.java index b0b42bc..bd88d61 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/web/BookController.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/web/BookController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import xyz.zinglizingli.books.core.config.SeoConfig; import xyz.zinglizingli.books.po.Book; import xyz.zinglizingli.books.po.BookContent; import xyz.zinglizingli.books.po.BookIndex; @@ -23,6 +24,7 @@ import xyz.zinglizingli.common.cache.CommonCacheUtil; import xyz.zinglizingli.books.core.utils.CatUtil; import xyz.zinglizingli.books.core.utils.Constants; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.OutputStream; @@ -48,6 +50,7 @@ public class BookController { private final CommonCacheUtil commonCacheUtil; + /** * 精品小说搜索页 */ @@ -180,7 +183,7 @@ public class BookController { * 书籍详情页 */ @RequestMapping("{bookId}.html") - public String detail(@PathVariable("bookId") Long bookId, @RequestParam(value = "token", required = false) String token, ModelMap modelMap) { + public String detail(@PathVariable("bookId") Long bookId, @RequestParam(value = "token", required = false) String token, HttpServletRequest req, ModelMap modelMap) { String userId = commonCacheUtil.get(token); if (org.apache.commons.lang3.StringUtils.isNotBlank(userId)) { Integer indexNumber = userService.queryBookIndexNumber(userId, bookId); @@ -215,6 +218,12 @@ public class BookController { modelMap.put("lastIndexName", indexList.get(0).getIndexName()); modelMap.put("lastIndexNum", indexList.get(0).getIndexNum()); } + SeoConfig seoConfig = (SeoConfig) req.getServletContext().getAttribute(Constants.SEO_CONFIG_KEY); + Map page = seoConfig.getPage(); + page.put("detail.title",page.get("detail.title").replaceAll("",book.getBookName())); + page.put("detail.keyword",page.get("detail.keyword").replaceAll("",book.getBookName())); + page.put("detail.description",page.get("detail.description").replaceAll("",book.getBookName())); + return "books/book_detail"; } @@ -222,12 +231,17 @@ public class BookController { * 书籍目录页 */ @RequestMapping("{bookId}/index.html") - public String bookIndex(@PathVariable("bookId") Long bookId, ModelMap modelMap) { + public String bookIndex(@PathVariable("bookId") Long bookId,HttpServletRequest req, ModelMap modelMap) { List indexList = bookService.queryAllIndexList(bookId); String bookName = bookService.queryBaseInfo(bookId).getBookName(); modelMap.put("indexList", indexList); modelMap.put("bookName", bookName); modelMap.put("bookId", bookId); + SeoConfig seoConfig = (SeoConfig) req.getServletContext().getAttribute(Constants.SEO_CONFIG_KEY); + Map page = seoConfig.getPage(); + page.put("catalog.title",page.get("catalog.title").replaceAll("",bookName)); + page.put("catalog.keyword",page.get("catalog.keyword").replaceAll("",bookName)); + page.put("catalog.description",page.get("catalog.description").replaceAll("",bookName)); return "books/book_index"; } @@ -236,7 +250,7 @@ public class BookController { * 书籍内容页 */ @RequestMapping("{bookId}/{indexNum}.html") - public String bookContent(@PathVariable("bookId") Long bookId, @PathVariable("indexNum") Integer indexNum, ModelMap modelMap) { + public String bookContent(@PathVariable("bookId") Long bookId, @PathVariable("indexNum") Integer indexNum,HttpServletRequest req, ModelMap modelMap) { BookContent bookContent = bookService.queryBookContent(bookId, indexNum); String indexName; if (bookContent == null) { @@ -263,6 +277,11 @@ public class BookController { Integer catId = basicBook.getCatid(); modelMap.put("bookName", bookName); modelMap.put("catId", catId); + SeoConfig seoConfig = (SeoConfig) req.getServletContext().getAttribute(Constants.SEO_CONFIG_KEY); + Map page = seoConfig.getPage(); + page.put("content.title",page.get("content.title").replaceAll("",bookName).replaceAll("",indexName)); + page.put("content.keyword",page.get("content.keyword").replaceAll("",bookName).replaceAll("",indexName)); + page.put("content.description",page.get("content.description").replaceAll("",bookName).replaceAll("",indexName)); return "books/book_content"; } diff --git a/novel-front/src/main/resources/application-website.yml b/novel-front/src/main/resources/application-website.yml new file mode 100644 index 0000000..f910388 --- /dev/null +++ b/novel-front/src/main/resources/application-website.yml @@ -0,0 +1,43 @@ +#网站配置 +website: + #网站名 + name: 笔趣阁新书门 + #域名 + domain: https://www.xinshumen.com + #页面配置 + page: + #首页配置 + index: + title: ${website.name} + keyword: ${website.name},精品小说,弹幕网站,弹幕,弹幕小说网站,免费小说,小说阅读,小说排行,轻小说,txt小说下载,电子书下载,动漫轻小说,日本轻小说 + description: ${website.name}是国内优秀的小说弹幕网站,${website.name}提供海量热门网络小说,日本轻小说,国产轻小说,动漫小说,轻小说在线阅读和TXT小说下载,致力于网络精品小说的收集,智能计算小说评分,打造小说精品排行榜,致力于无广告无弹窗的小说阅读环境。 + #小说列表页配置 + book-search: + title: ${website.name}_列表 + keyword: ${website.name},精品小说,弹幕网站,弹幕,弹幕小说网站,免费小说,小说阅读,小说排行,轻小说,txt小说下载,电子书下载,动漫轻小说,日本轻小说 + description: ${website.name}是国内优秀的小说弹幕网站,${website.name}提供海量热门网络小说,日本轻小说,国产轻小说,动漫小说,轻小说在线阅读和TXT小说下载,致力于网络精品小说的收集,智能计算小说评分,打造小说精品排行榜,致力于无广告无弹窗的小说阅读环境。 + #轻小说列表页配置 + soft-search: + title: ${website.name}_轻小说专区 + keyword: ${website.name},精品小说,弹幕网站,弹幕,弹幕小说网站,免费小说,小说阅读,小说排行,轻小说,txt小说下载,电子书下载,动漫轻小说,日本轻小说 + description: ${website.name}是国内优秀的小说弹幕网站,${website.name}提供海量热门网络小说,日本轻小说,国产轻小说,动漫小说,轻小说在线阅读和TXT小说下载,致力于网络精品小说的收集,智能计算小说评分,打造小说精品排行榜,致力于无广告无弹窗的小说阅读环境。 + #漫画列表页配置 + mh-search: + title: ${website.name}_漫画专区 + keyword: ${website.name},精品小说,弹幕网站,弹幕,弹幕小说网站,免费小说,小说阅读,小说排行,轻小说,txt小说下载,电子书下载,动漫轻小说,日本轻小说 + description: ${website.name}是国内优秀的小说弹幕网站,${website.name}提供海量热门网络小说,日本轻小说,国产轻小说,动漫小说,轻小说在线阅读和TXT小说下载,致力于网络精品小说的收集,智能计算小说评分,打造小说精品排行榜,致力于无广告无弹窗的小说阅读环境。 + #目录页配置 + catalog: + title: 最新免费章节目录列表 + keyword: ,最新章节 + description: 最新章节列表,最新更新章节免费无广告无弹窗在线阅读TXT下载。 + #书籍详情页配置 + detail: + title: 小说最新章节免费阅读和下载 + keyword: ,最新章节,免费阅读,TXT下载 + description: 最新章节列表,最新更新章节免费无广告无弹窗在线阅读,小说TXT免费下载。 + #书籍内容页配置 + content: + title: + keyword: , + description: 最新更新章节免费在线阅读TXT下载 \ No newline at end of file diff --git a/novel-front/src/main/resources/application.yml b/novel-front/src/main/resources/application.yml index eef66ae..f8e9137 100644 --- a/novel-front/src/main/resources/application.yml +++ b/novel-front/src/main/resources/application.yml @@ -1,6 +1,3 @@ -website: - name: 笔趣阁新书门 - server: port: 8080 @@ -43,7 +40,7 @@ spring: class: javax.net.ssl.SSLSocketFactory fallback: false profiles: - include: crawl + include: crawl,website diff --git a/novel-front/src/main/resources/templates/books/book_content.html b/novel-front/src/main/resources/templates/books/book_content.html index 2ba93f8..cdad521 100644 --- a/novel-front/src/main/resources/templates/books/book_content.html +++ b/novel-front/src/main/resources/templates/books/book_content.html @@ -4,15 +4,16 @@ - + + + - + th:content="${application.seoConfig.page['content.description']}"> - - + +
diff --git a/novel-front/src/main/resources/templates/books/book_detail.html b/novel-front/src/main/resources/templates/books/book_detail.html index b2a69ae..5235db3 100644 --- a/novel-front/src/main/resources/templates/books/book_detail.html +++ b/novel-front/src/main/resources/templates/books/book_detail.html @@ -3,24 +3,26 @@ - - + + + + + th:content="${application.seoConfig.page['detail.description']}"> - + - + - - + + - + diff --git a/novel-front/src/main/resources/templates/books/book_index.html b/novel-front/src/main/resources/templates/books/book_index.html index 417018f..5f9f48e 100644 --- a/novel-front/src/main/resources/templates/books/book_index.html +++ b/novel-front/src/main/resources/templates/books/book_index.html @@ -5,14 +5,16 @@ - - + + + + + th:content="${application.seoConfig.page['catalog.description']}"> - - + + diff --git a/novel-front/src/main/resources/templates/books/book_search.html b/novel-front/src/main/resources/templates/books/book_search.html index 35a6be6..8afc1db 100644 --- a/novel-front/src/main/resources/templates/books/book_search.html +++ b/novel-front/src/main/resources/templates/books/book_search.html @@ -5,12 +5,12 @@ - + - + + th:content="${application.seoConfig.page['book-search.description']}">
diff --git a/novel-front/src/main/resources/templates/books/index.html b/novel-front/src/main/resources/templates/books/index.html index 77f9c58..f8bb33c 100644 --- a/novel-front/src/main/resources/templates/books/index.html +++ b/novel-front/src/main/resources/templates/books/index.html @@ -5,17 +5,17 @@ - + - + + th:content="${application.seoConfig.page['index.description']}"> - + + th:content="${application.seoConfig.page['index.description']}"/>
diff --git a/novel-front/src/main/resources/templates/books/mh_book_search.html b/novel-front/src/main/resources/templates/books/mh_book_search.html index 2075f20..d5eb72a 100644 --- a/novel-front/src/main/resources/templates/books/mh_book_search.html +++ b/novel-front/src/main/resources/templates/books/mh_book_search.html @@ -5,18 +5,12 @@ - + - + - - - - - + th:content="${application.seoConfig.page['mh-search.description']}">
diff --git a/novel-front/src/main/resources/templates/books/soft_book_search.html b/novel-front/src/main/resources/templates/books/soft_book_search.html index 038893d..81037a6 100644 --- a/novel-front/src/main/resources/templates/books/soft_book_search.html +++ b/novel-front/src/main/resources/templates/books/soft_book_search.html @@ -5,18 +5,12 @@ - + - + - - - - - + th:content="${application.seoConfig.page['soft-search.description']}">
diff --git a/novel-front/src/main/resources/templates/user/login.html b/novel-front/src/main/resources/templates/user/login.html index 13ee0a9..f2250fa 100644 --- a/novel-front/src/main/resources/templates/user/login.html +++ b/novel-front/src/main/resources/templates/user/login.html @@ -6,8 +6,6 @@ 登录|注册 -