Merge branch 'USVT-126' into 'master'

USVT-127 测试下站点地图的动态化处理

See merge request usvisatrack/usvisatrack.api.service!11
This commit is contained in:
YuCheng Hu 2022-12-15 20:17:36 +00:00
commit a5f4b67381
2 changed files with 86 additions and 12 deletions

24
pom.xml
View File

@ -52,23 +52,29 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
@ -95,23 +101,17 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<groupId>com.ossez</groupId>
<artifactId>sitemap-j</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- swagger -->
<dependency>
<groupId>org.springdoc</groupId>

View File

@ -0,0 +1,74 @@
package com.northtecom.visatrack.api.controller.api;
import com.northtecom.visatrack.api.service.impl.BlogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
/**
* The API related to website content.
* <h2>Sitemap</h2>
* To increase website index, we need to submit sitemap to search engine, sitemap is the file to let search engine know
* which links they should get indexed.
*
* @Author: YuCheng
*/
@RestController
@RequestMapping(ContentController.BASE_URL)
@Tag(name = ContentController.TAG_NAME, description = ContentController.TAG_DESCRIPTION)
public class ContentController {
protected static final String BASE_URL = "/api/content";
protected static final String DATA_NAME = "Content";
protected static final String TAG_NAME = "Content";
protected static final String TAG_DESCRIPTION = "Content management API";
private final BlogService blogService;
public ContentController(BlogService blogService) {
this.blogService = blogService;
}
/**
* This API will provide sitemap as sitemap.xml file
*
* @return a File with Spring MVC
*/
@GetMapping("/sitemap")
@Operation(summary = "Get Sitemap xml file", description = "This API will get sitemap xml file")
public String querySitemap() {
byte[] bt = null;
String btx = null;
// bt = FileUtils.readFileToByteArray(new File("D:\\home\\sitemap.xml"));
btx = "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n" +
"<sitemap>\n" +
"<loc>https://www.ossez.com/sitemap_recent.xml</loc>\n" +
"<lastmod>2022-12-15T05:44:41Z</lastmod>\n" +
"</sitemap>\n" +
"<sitemap>\n" +
"<loc>https://www.ossez.com/sitemap_1.xml</loc>\n" +
"<lastmod>2022-12-15T05:44:41Z</lastmod>\n" +
"</sitemap>\n" +
"<sitemap>\n" +
"<loc>https://www.ossez.com/sitemap_2.xml</loc>\n" +
"<lastmod>2022-12-12T15:49:36Z</lastmod>\n" +
"</sitemap>\n" +
"</sitemapindex>";
// return Base64.getEncoder().withoutPadding().encodeToString(bt);
return btx;
}
}