Skip to content

Commit ab51486

Browse files
committed
refactor: refactoring page template usage logic
1 parent 8928105 commit ab51486

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

layout/_partial/scripts.ejs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<!-- common -->
1+
<%
2+
const { links: links_data, photos: photos_data, tools: tools_data } = theme?.source_data
3+
const page_template = page?.template?.toLowerCase()
4+
%>
5+
6+
<!-- common js -->
27
<%- __js([
38
'js/utils.js',
49
'js/header-shrink.js',
@@ -9,7 +14,7 @@
914
'js/libs/anime.min.js'
1015
]) %>
1116
12-
<!-- local-search -->
17+
<!-- local search -->
1318
<% if (theme?.local_search?.enable === true) { %>
1419
<%- __js('js/local-search.js') %>
1520
<% } %>
@@ -52,17 +57,17 @@
5257
<% } %>
5358
5459
<!-- links page -->
55-
<% if (is_current('/links') || is_current('/link')) { %>
60+
<% if ((page_template === 'links' || page_template === 'link') && links_data) { %>
5661
<%- __js('js/page/links-page.js') %>
5762
<% } %>
5863
5964
<!-- photos page -->
60-
<% if (is_current('/photos') || is_current('/photo')) { %>
65+
<% if ((page_template === 'photos' || page_template === 'photo') && photos_data) { %>
6166
<%- __js('js/page/photos-page.js') %>
6267
<% } %>
6368
6469
<!-- tools page -->
65-
<% if (is_current('/tools') || is_current('/tool')) { %>
70+
<% if ((page_template === 'tools' || page_template === 'tool') && tools_data) { %>
6671
<%- __js('js/page/tools-page.js') %>
6772
<% } %>
6873
</div>

layout/_template/page-template.ejs

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
11
<%
22
const page_title = page?.title?.toLowerCase()
3+
const page_template = page?.template?.toLowerCase()
34
const use_page_template = page?.use_template !== false
45
const { links: links_data, photos: photos_data, tools: tools_data } = theme?.source_data
5-
const has_page_cover = page?.page_cover ? 'has-page-cover' : ''
66
77
let current_page_data = null
88
let current_page_template = null
99
let keep_container = 'keep-container'
1010
11-
if (page_title === 'links' || page_title === 'link') {
11+
if (page_template === 'links' || page_template === 'link') {
1212
current_page_data = links_data
1313
current_page_template = 'friends-link'
1414
}
1515
16-
if (page_title === 'photos' || page_title === 'photo') {
16+
if (page_template === 'photos' || page_template === 'photo') {
1717
current_page_data = photos_data
1818
current_page_template = 'photo-album'
1919
}
2020
21-
if (page_title === 'tools' || page_title === 'tool') {
21+
if (page_template === 'tools' || page_template === 'tool') {
2222
current_page_data = tools_data
2323
current_page_template = 'tools-nav'
2424
if (current_page_data) { keep_container = '' }
2525
}
26+
27+
const page_cover = page?.page_cover || ''
28+
const has_page_cover = page_cover ? 'has-page-cover' : ''
29+
const page_cover_title = page?.page_cover_title || ''
30+
const page_cover_height = page?.page_cover_height ? page?.page_cover_height + 'px' : '200px'
2631
%>
32+
2733
<div class="fade-in-down-animation">
2834
<div class="page-template-container border-box <%= keep_container %> <%= has_page_cover %>">
2935
<!-- page top -->
3036
<% if (page?.page_cover) { %>
3137
<div class="page-template-top border-box"
32-
style="height: <%= page?.page_cover_height ? page?.page_cover_height + 'px' : '200px' %>"
38+
style="height: <%= page_cover_height %>"
3339
>
34-
<img class="page-cover" src="<%- url_for(page.page_cover) %>"
40+
<img class="page-cover" src="<%- url_for(page_cover) %>"
3541
onerror="this.style.display = 'none'"
3642
>
43+
<% if (page_cover_title) { %>
44+
<span class="page-cover-title">
45+
<%= page_cover_title %>
46+
</span>
47+
<% } %>
3748
</div>
3849
<% } %>
3950

source/css/layout/_template/page-template.styl

+17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ $page-container-gap = 2rem
3434
height 100%
3535
object-fit cover
3636
}
37+
38+
.page-cover-title {
39+
position absolute
40+
bottom 1rem
41+
left 1rem
42+
box-sizing border-box
43+
padding 1rem 1.6rem
44+
overflow-y auto
45+
color var(--text-color-3)
46+
font-weight 600
47+
font-size 1.6rem
48+
line-height 1.6
49+
background var(--background-color-1-transparent)
50+
border-radius var(--box-border-radius)
51+
-webkit-backdrop-filter blur(1px)
52+
backdrop-filter blur(1px)
53+
}
3754
}
3855

3956

0 commit comments

Comments
 (0)