增加sitemap.xml
This commit is contained in:
@@ -186,27 +186,27 @@ namespace COMCMS.Web.Controllers
|
|||||||
|
|
||||||
#region 测试
|
#region 测试
|
||||||
//[Route("c/{*path}/index2.html")]
|
//[Route("c/{*path}/index2.html")]
|
||||||
public IActionResult Test(string path = "")
|
//public IActionResult Test(string path = "")
|
||||||
{
|
//{
|
||||||
var asms = AppDomain.CurrentDomain.GetAssemblies();
|
// var asms = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
List<string> list = new List<string>();
|
// List<string> list = new List<string>();
|
||||||
foreach (var item in asms)
|
// foreach (var item in asms)
|
||||||
{
|
// {
|
||||||
string fullName = item.GetName().ToString();
|
// string fullName = item.GetName().ToString();
|
||||||
if (fullName.IndexOf("COMCMS.Web.Views")>-1)
|
// if (fullName.IndexOf("COMCMS.Web.Views")>-1)
|
||||||
{
|
// {
|
||||||
var types = item.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
|
// var types = item.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
|
||||||
foreach (var type in types)
|
// foreach (var type in types)
|
||||||
{
|
// {
|
||||||
string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
|
// string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
|
||||||
list.Add(viewName);
|
// list.Add(viewName);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
//list.Add(item.GetName().ToString());
|
// //list.Add(item.GetName().ToString());
|
||||||
}
|
// }
|
||||||
return Content(JsonConvert.SerializeObject(list));
|
// return Content(JsonConvert.SerializeObject(list));
|
||||||
}
|
//}
|
||||||
//[Route("{path1:regex([[a-zA-Z0-9-]])}/{path2:regex([[a-zA-Z0-9-]])}/index.html")]
|
//[Route("{path1:regex([[a-zA-Z0-9-]])}/{path2:regex([[a-zA-Z0-9-]])}/index.html")]
|
||||||
//public IActionResult Test2(string path1 = "", string path2 = "")
|
//public IActionResult Test2(string path1 = "", string path2 = "")
|
||||||
//{
|
//{
|
||||||
@@ -425,6 +425,25 @@ namespace COMCMS.Web.Controllers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region sitemap html
|
||||||
|
[Route("sitemap.html")]
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult SitemapHTML()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region sitemap xml
|
||||||
|
[HttpGet]
|
||||||
|
[Route("sitemap.xml")]
|
||||||
|
public IActionResult SitemapXML()
|
||||||
|
{
|
||||||
|
Response.ContentType = "text/xml";
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
@{
|
||||||
|
Layout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<title>SitemapHTML</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
@{
|
||||||
|
Layout = "~/Views/Shared/_SitemapLayout.cshtml";
|
||||||
|
string url = Utils.GetServerUrl();
|
||||||
|
string lastmod = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
|
//所有文章栏目
|
||||||
|
IList<ArticleCategory> articleCategories = ArticleCategory.FindAll(ArticleCategory._.IsHide == 0, null, null, 0, 0);
|
||||||
|
//前2000篇文章
|
||||||
|
IList<Article> articles = Article.FindAll(Article._.IsHide == 0, null, null, 0, 2000);
|
||||||
|
}
|
||||||
|
<url>
|
||||||
|
<loc>@url</loc>
|
||||||
|
<priority>1.0</priority>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
@foreach (var item in articleCategories)
|
||||||
|
{
|
||||||
|
<url>
|
||||||
|
<loc>@(url)/article/index/@(item.Id)</loc>
|
||||||
|
<priority>0.80</priority>
|
||||||
|
<lastmod>@(lastmod)</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
}
|
||||||
|
@foreach (var item in articles)
|
||||||
|
{
|
||||||
|
<url>
|
||||||
|
<loc>@(url)/article/detail/@(item.Id)</loc>
|
||||||
|
<priority>0.80</priority>
|
||||||
|
<lastmod>@(lastmod)</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<urlset>
|
||||||
|
@RenderBody()
|
||||||
|
</urlset>
|
||||||
Reference in New Issue
Block a user