Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature dev #45

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/content/getting-started/publish-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ deploy:
buildDir: dist
username: devlive-community
email: [email protected]
```

使用以下命令发布到 Github Pages:

```bash
pageforge deploy-github
```
10 changes: 6 additions & 4 deletions lib/indexer-generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const { isFeatureEnabled } = require('./utils');
const {isFeatureEnabled} = require('./utils');

class SearchIndexBuilder {
constructor(config, pages, getNavigation) {
Expand All @@ -18,7 +18,9 @@ class SearchIndexBuilder {

// 处理导航项
processNavItem(item, lang) {
if (!item) return;
if (!item) {
return;
}

if (item.href) {
// 将 /.html 转换为 /index.html
Expand All @@ -32,7 +34,7 @@ class SearchIndexBuilder {
const filePath = this.getFilePath(normalizedHref);
if (filePath && fs.existsSync(filePath)) {
const content = fs.readFileSync(filePath, 'utf-8');
const { title, processedContent } = this.parseContent(content, filePath);
const {title, processedContent} = this.parseContent(content, filePath);

// 构建搜索项
const searchItem = {
Expand Down Expand Up @@ -101,7 +103,7 @@ class SearchIndexBuilder {
// 清理 Markdown 语法
processedContent = this.cleanMarkdown(processedContent);

return { title, processedContent };
return {title, processedContent};
}

// 清理 Markdown 语法
Expand Down
13 changes: 7 additions & 6 deletions templates/assets/js/pageforge-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,23 @@ const Search = {
this.els.searchResults.innerHTML = `
<div class="divide-y divide-gray-100 dark:divide-gray-800">
${results.map(result => {
const highlightedTitle = this.highlightText(result.title, query);
const contentExcerpt = this.getContentExcerpt(result.content, query);
const highlightedContent = this.highlightText(contentExcerpt, query);

return `
const highlightedTitle = this.highlightText(result.title, query);
const contentExcerpt = this.getContentExcerpt(result.content, query);
const highlightedContent = this.highlightText(contentExcerpt, query);
return `
<a href="${result.url}"
class="block px-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700/50">
<div class="text-sm font-medium text-gray-900 dark:text-gray-100">
${highlightedTitle}
${result.lang ? `<span class="ml-2 text-xs px-1.5 py-0.5 rounded-full bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300">${result.lang}</span>` : ''}
</div>
<div class="mt-1 text-sm text-gray-500 dark:text-gray-400 line-clamp-2">
${highlightedContent}
</div>
</a>
`;
}).join('')}
}).join('')}
</div>
`;
}
Expand Down
33 changes: 18 additions & 15 deletions templates/includes/header-nav.ejs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<ul class="hidden lg:flex items-center gap-6 md:gap-8 py-3">
<% for(let item of siteData.nav) { %>
<li class="shrink-0">
<a href="<%= pageData.language ? `/${pageData.language}${item.href}` : item.href %>"
class="inline-flex items-center rounded-lg justify-center px-4 py-3
text-sm font-medium leading-none <%= darkClasses('dark:text-white') %>
<%= isPathInNavItem(pageData.noLocalePath, item)
? `text-blue-600 ${darkClasses('dark:text-blue-400')} bg-blue-50/80 ${darkClasses('dark:bg-blue-900/20')} font-medium`
: `hover:text-gray-900 ${darkClasses('dark:hover:text-gray-200')} hover:bg-gray-50 ${darkClasses('dark:hover:bg-gray-800/40')}`
%>">
<%= item.title %>
</a>
</li>
<% } %>
</ul>
<div class="hidden lg:flex items-center gap-2 overflow-x-auto py-3 [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
<ul class="flex items-center gap-2 shrink-0">
<% for(let item of siteData.nav) { %>
<li class="shrink-0">
<a href="<%= pageData.language ? `/${pageData.language}${item.href}` : item.href %>"
class="inline-flex items-center rounded-lg justify-center px-3.5 py-3
text-sm font-medium leading-none whitespace-nowrap
<%= darkClasses('dark:text-white') %>
<%= isPathInNavItem(pageData.noLocalePath, item)
? `text-blue-600 ${darkClasses('dark:text-blue-400')} bg-blue-50/80 ${darkClasses('dark:bg-blue-900/20')} font-medium`
: `hover:text-gray-900 ${darkClasses('dark:hover:text-gray-200')} hover:bg-gray-50 ${darkClasses('dark:hover:bg-gray-800/40')}`
%>">
<%= item.title %>
</a>
</li>
<% } %>
</ul>
</div>
6 changes: 3 additions & 3 deletions templates/includes/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ const darkClasses = (classes) => darkModeEnabled ? classes : '';

<!-- 桌面端导航 -->
<%- include('./header-nav', { darkClasses, isPathInNavItem }) %>

<!-- 搜索框 -->
<%- include('./header-search', { darkClasses }) %>
</div>

<!-- 右侧工具栏 -->
<div class="flex items-center gap-2 lg:gap-4">
<!-- 搜索框 -->
<%- include('./header-search', { darkClasses }) %>

<!-- 桌面端主题切换按钮 -->
<% if (darkModeEnabled) { %>
<button type="button"
Expand Down