Skip to content

Commit

Permalink
merge from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
niltor committed Apr 2, 2024
2 parents 63a153a + c1f52a2 commit 3c6468e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
10 changes: 5 additions & 5 deletions Lib/BuildSite/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private string GenBlogListHtml(Catalog rootCatalog, WebInfo webInfo)
<p class="text-neutral-700 text-base dark:text-neutral-300">
👨‍💻 {webInfo?.AuthorName}
&nbsp;&nbsp;
⏱️ <span class="publish-time" data-time="{blog.PublishTime:yyyy-MM-ddThh:mm:sszzz}"></span>
⏱️ <span class="publish-time" data-time="{blog.PublishTime:yyyy-MM-ddTHH:mm:sszzz}"></span>
</p>
</div>
</div>
Expand All @@ -354,7 +354,7 @@ private string GenSiderBar(Catalog data)
var allBlogs = data?.GetAllBlogs().OrderByDescending(b => b.PublishTime).ToList() ?? [];
var dates = allBlogs!.Select(b => b.PublishTime)
.OrderByDescending(b => b)
.DistinctBy(b => b.Date)
.DistinctBy(b => b.ToString("yyyy-MM"))
.ToList();

sb.AppendLine("<div id=\"catalog-list\" class=\"rounded-lg shadow-md p-4 dark:bg-neutral-800\">");
Expand Down Expand Up @@ -385,10 +385,10 @@ 全部 [{allBlogs.Count}]
""");
foreach (var date in dates)
{
var count = allBlogs.Count(b => b.PublishTime.Date == date.Date);
var count = allBlogs.Count(b => b.PublishTime.Year == date.Year && b.PublishTime.Month == date.Month);
var html = $"""
<span data-date="{date:yyyy-MM-dd}" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
{date:yyyy-MM-dd} [{count}]
<span data-date="{date:yyyy-MM}" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
{date:yyyy-MM} [{count}]
</span>
""";
sb.AppendLine(html);
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@

fork之后,你将拥有所有的自定义权限,因为所有的源代码都已经在你自己的仓库中。

核心项目为`BuildSite`该项目是用来生成数据文件的,其中包括将markdown文件转换成html文件。
核心项目为`BuildSite`用来生成静态文件,其中包括将markdown文件转换成html文件。

你需要准备以下内容以便进行二次开发
### 开发环境

- .NET SDK 8.0,以便运行 `BuildSite`项目
- tailwindcss,生成css样式内容
`BuildSite`项目是一个.NET项目,你需要安装.NET SDK 8.0。

此外,你可以安装(可选)

- tailwindcss,用来生成css样式内容
- http-server,用来启动本地静态内容,以便调试

### 运行项目
Expand All @@ -101,7 +104,7 @@ fork之后,你将拥有所有的自定义权限,因为所有的源代码都
2. 或者直接运行根目录下的`build.ps1`脚本。
3. 刷新浏览器,可看到最新生成的内容。

> 如果你使用`tailwindcss`请在`WebApp`下执行`npx tailwindcss -o ./css/app.css --watch`
如果你使用`tailwindcss`可在`WebApp`下执行`npx tailwindcss -o ./css/app.css --watch`

### 自定义主页内容

Expand Down
1 change: 1 addition & 0 deletions WebApp/css/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ h5 {
border-radius: 5px;
padding: 8px;
height: fit-content;
min-width: 240px;
}


Expand Down
4 changes: 2 additions & 2 deletions WebApp/data/blogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"Title": "Markdown支持示例",
"Path": "/Markdown%E6%94%AF%E6%8C%81%E7%A4%BA%E4%BE%8B.html",
"FileName": "Markdown支持示例.md",
"PublishTime": "2024-04-01T15:55:38+08:00",
"PublishTime": "2024-04-01T16:49:23+08:00",
"CreatedTime": "2024-04-01T14:45:14+08:00",
"UpdatedTime": "2024-04-01T15:55:38+08:00",
"UpdatedTime": "2024-04-01T16:49:23+08:00",
"Catalog": null
}
],
Expand Down
6 changes: 3 additions & 3 deletions WebApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<p class="text-neutral-700 text-base dark:text-neutral-300">
👨‍💻 NilTor
&nbsp;&nbsp;
⏱️ <span class="publish-time" data-time="2024-04-01T03:55:38+08:00"></span>
⏱️ <span class="publish-time" data-time="2024-04-01T16:49:23+08:00"></span>
</p>
</div>
</div>
Expand Down Expand Up @@ -74,8 +74,8 @@
<span data-date="all" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
全部 [2]
</span>
<span data-date="2024-04-01" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
2024-04-01 [2]
<span data-date="2024-04" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
2024-04 [2]
</span>
</div>

Expand Down
13 changes: 3 additions & 10 deletions WebApp/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function filterBlogs(catalogName, date) {
blogs = catalog.Blogs;
} else if (date != 'all') {

blogs = allBlogs.filter(blog => blog.PublishTime.split('T')[0] == date);
blogs = allBlogs.filter(blog => blog.PublishTime.substr(0, 7) == date);
} else {
blogs = allBlogs.slice(0, 50);

Expand Down Expand Up @@ -103,20 +103,19 @@ function renderBlogs() {
blogLink.href = './blogs' + blog.Path;
blogLink.target = '_blank';
blogLink.className = 'block text-lg py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100';
blogLink.innerText = blog.Title;
blogLink.innerText = "📑 " + blog.Title;
blogTitleDiv.appendChild(blogLink);
blogInnerDiv.appendChild(blogTitleDiv);
let blogInfoP = document.createElement('p');
blogInfoP.className = 'text-neutral-700 text-base dark:text-neutral-300';
blogInfoP.innerHTML = `👨‍💻 ${webInfo.Name} &nbsp;&nbsp; ⏱️ ${blog.DisplayDate}`;
blogInfoP.innerHTML = `👨‍💻 ${webInfo.AuthorName} &nbsp;&nbsp; ⏱️ ${timeAgo(new Date(blog.PublishTime))}`;
blogInnerDiv.appendChild(blogInfoP);
blogDiv.appendChild(blogInnerDiv);
blogList.appendChild(blogDiv);
});
}

function timeAgo(date) {
console.log(date);
const seconds = Math.floor((new Date() - date) / 1000);
const intervals = {
'年': 31536000,
Expand Down Expand Up @@ -159,9 +158,3 @@ function timeAgo(date) {

return '刚刚';
}

const date1 = new Date('2024-03-31T12:00:00');
console.log(timeAgo(date1)); // 输出: 1天前

const date2 = new Date('2023-01-01T00:00:00');
console.log(timeAgo(date2)); // 输出: 1年3个月前

0 comments on commit 3c6468e

Please sign in to comment.