jekyll-vitepress-theme 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/assets/css/vitepress-overrides.css +13 -2
- data/assets/js/vitepress-theme.js +61 -5
- data/lib/jekyll/vitepress_theme/hooks.rb +57 -23
- data/lib/jekyll/vitepress_theme/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66fe5075d52518e812e3a2d8f6e17af3ac03678587c4ba791e577189b725374f
|
|
4
|
+
data.tar.gz: 692859f3b2f76e628a59235a565cd4837663e663896d0d0770ac2ab123b2dc62
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 99c56f6757de3f76dd02188eb5f044b65d431b094153b75ea69c88cfc5af427a3467a3a96cf4e07c5434899b5942a8f00ad7b0886b0db39f816f3fff6ac3548f
|
|
7
|
+
data.tar.gz: a6abce7ca7eaf12ec365ad41eb800f7f9ca7d470851670eda401979f7c45f8e499766d7c2fb9aff72702f52fbda95cbb017b4c4f8711f11d7dd19db9de7f44e1
|
|
@@ -1700,15 +1700,26 @@ html.dark .only-light {
|
|
|
1700
1700
|
}
|
|
1701
1701
|
|
|
1702
1702
|
/* Copy as Markdown button group */
|
|
1703
|
-
.vp-doc-header
|
|
1703
|
+
.vp-doc-header,
|
|
1704
|
+
.vp-doc-title-row {
|
|
1704
1705
|
display: flex;
|
|
1705
1706
|
align-items: center;
|
|
1706
1707
|
justify-content: space-between;
|
|
1707
1708
|
gap: 12px;
|
|
1709
|
+
flex-wrap: wrap;
|
|
1708
1710
|
}
|
|
1709
1711
|
|
|
1710
|
-
.vp-doc-header h1
|
|
1712
|
+
.vp-doc-header h1,
|
|
1713
|
+
.vp-doc-title-row h1 {
|
|
1711
1714
|
margin-top: 0;
|
|
1715
|
+
margin-bottom: 0;
|
|
1716
|
+
flex: 1 1 320px;
|
|
1717
|
+
min-width: 0;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
.vp-doc-header .copy-md-group,
|
|
1721
|
+
.vp-doc-title-row .copy-md-group {
|
|
1722
|
+
margin-left: auto;
|
|
1712
1723
|
}
|
|
1713
1724
|
|
|
1714
1725
|
/* Copy page icon defs */
|
|
@@ -1164,16 +1164,72 @@
|
|
|
1164
1164
|
addCopyButtons();
|
|
1165
1165
|
|
|
1166
1166
|
// Copy page as Markdown - split button with dropdown
|
|
1167
|
+
function markdownStartsWithH1(markdown) {
|
|
1168
|
+
var value = String(markdown || '').replace(/^\s+/, '');
|
|
1169
|
+
return /^#\s+\S/.test(value) || /^<h1(?:\s|>)/i.test(value) || /^[^\n]+\n=+\s*(?:\n|$)/.test(value);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function resolveCopyPageTitleHeading() {
|
|
1173
|
+
var doc = document.querySelector('.vp-doc');
|
|
1174
|
+
if (!doc) {
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
var headerHeading = doc.querySelector('.vp-doc-header h1');
|
|
1179
|
+
if (headerHeading) {
|
|
1180
|
+
return headerHeading;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
var headings = Array.from(doc.querySelectorAll('h1'));
|
|
1184
|
+
for (var i = 0; i < headings.length; i += 1) {
|
|
1185
|
+
if (!headings[i].closest('.vp-doc-header')) {
|
|
1186
|
+
return headings[i];
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
function alignCopyPageButtonWithHeading() {
|
|
1194
|
+
var header = document.querySelector('.vp-doc-header');
|
|
1195
|
+
var group = header && header.querySelector('.copy-md-group');
|
|
1196
|
+
if (!header || !group || header.querySelector('h1')) {
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
var titleHeading = resolveCopyPageTitleHeading();
|
|
1201
|
+
if (!titleHeading) {
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
var titleRow = titleHeading.closest('.vp-doc-title-row');
|
|
1206
|
+
if (!titleRow) {
|
|
1207
|
+
titleRow = document.createElement('div');
|
|
1208
|
+
titleRow.className = 'vp-doc-title-row';
|
|
1209
|
+
titleHeading.parentNode.insertBefore(titleRow, titleHeading);
|
|
1210
|
+
titleRow.appendChild(titleHeading);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
titleRow.appendChild(group);
|
|
1214
|
+
|
|
1215
|
+
if (!header.querySelector('*')) {
|
|
1216
|
+
header.hidden = true;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
alignCopyPageButtonWithHeading();
|
|
1221
|
+
|
|
1167
1222
|
function copyPageMarkdown(btn) {
|
|
1223
|
+
if (!btn) return;
|
|
1224
|
+
|
|
1168
1225
|
var textarea = document.querySelector('.vp-raw-markdown');
|
|
1169
1226
|
if (!textarea) return;
|
|
1170
1227
|
|
|
1171
1228
|
var md = textarea.value;
|
|
1172
|
-
if (
|
|
1173
|
-
var
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
var titleText = autoH1.textContent.trim();
|
|
1229
|
+
if (!markdownStartsWithH1(md)) {
|
|
1230
|
+
var titleHeading = resolveCopyPageTitleHeading();
|
|
1231
|
+
if (titleHeading) {
|
|
1232
|
+
var titleText = titleHeading.textContent.trim();
|
|
1177
1233
|
if (titleText) {
|
|
1178
1234
|
md = '# ' + titleText + '\n\n' + md;
|
|
1179
1235
|
}
|
|
@@ -104,6 +104,56 @@ module Jekyll
|
|
|
104
104
|
value.to_s.strip.casecmp(AUTO_VALUE).zero?
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
|
+
|
|
108
|
+
module CopyPage
|
|
109
|
+
module_function
|
|
110
|
+
|
|
111
|
+
def enabled?(item)
|
|
112
|
+
theme_config = item.site.config['jekyll_vitepress']
|
|
113
|
+
copy_page_disabled = theme_config.is_a?(Hash) &&
|
|
114
|
+
theme_config['copy_page'].is_a?(Hash) &&
|
|
115
|
+
theme_config['copy_page']['enabled'] == false
|
|
116
|
+
|
|
117
|
+
unless copy_page_disabled
|
|
118
|
+
page_theme = item.data['jekyll_vitepress']
|
|
119
|
+
copy_page_disabled = page_theme == false || (page_theme.is_a?(Hash) && page_theme['copy_page'] == false)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
!copy_page_disabled
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def resolved_markdown(item, payload)
|
|
126
|
+
raw = item.content.to_s
|
|
127
|
+
return raw unless item.respond_to?(:render_with_liquid?) && item.render_with_liquid?
|
|
128
|
+
|
|
129
|
+
item.renderer.render_liquid(raw, payload, liquid_render_info(item, payload), item.path)
|
|
130
|
+
rescue StandardError => e
|
|
131
|
+
relative_path = item.respond_to?(:relative_path) ? item.relative_path : item.path
|
|
132
|
+
Jekyll.logger.warn('jekyll-vitepress-theme', "Copy page markdown capture failed for #{relative_path}: #{e.message}")
|
|
133
|
+
raw
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def liquid_render_info(item, payload)
|
|
137
|
+
liquid_options = item.site.config['liquid'] || {}
|
|
138
|
+
|
|
139
|
+
{
|
|
140
|
+
registers: { site: item.site, page: payload['page'] },
|
|
141
|
+
strict_filters: liquid_options['strict_filters'],
|
|
142
|
+
strict_variables: liquid_options['strict_variables']
|
|
143
|
+
}
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def leading_h1?(markdown)
|
|
147
|
+
return false if markdown.nil?
|
|
148
|
+
|
|
149
|
+
stripped = markdown.lstrip
|
|
150
|
+
return false if stripped.empty?
|
|
151
|
+
|
|
152
|
+
stripped.match?(/\A#\s+\S/) ||
|
|
153
|
+
stripped.match?(/\A<h1(?:\s|>)/i) ||
|
|
154
|
+
stripped.match?(/\A[^\n]+\n=+\s*(?:\n|$)/)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
107
157
|
end
|
|
108
158
|
end
|
|
109
159
|
|
|
@@ -112,38 +162,22 @@ Jekyll::Hooks.register :site, :post_read do |site|
|
|
|
112
162
|
Jekyll::VitePressTheme::RougeStyles.apply(site)
|
|
113
163
|
end
|
|
114
164
|
|
|
115
|
-
Jekyll::Hooks.register :documents, :pre_render do |document|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
theme_config['copy_page'].is_a?(Hash) &&
|
|
119
|
-
theme_config['copy_page']['enabled'] == false
|
|
120
|
-
|
|
121
|
-
unless copy_page_disabled
|
|
122
|
-
page_theme = document.data['jekyll_vitepress']
|
|
123
|
-
copy_page_disabled = page_theme == false || (page_theme.is_a?(Hash) && page_theme['copy_page'] == false)
|
|
165
|
+
Jekyll::Hooks.register :documents, :pre_render do |document, payload|
|
|
166
|
+
if Jekyll::VitePressTheme::CopyPage.enabled?(document)
|
|
167
|
+
document.data['_raw_markdown'] = Jekyll::VitePressTheme::CopyPage.resolved_markdown(document, payload)
|
|
124
168
|
end
|
|
125
169
|
|
|
126
|
-
document.data['_raw_markdown'] = document.content unless copy_page_disabled
|
|
127
|
-
|
|
128
170
|
next if document.data.key?('last_updated_at')
|
|
129
171
|
|
|
130
172
|
updated_at = Jekyll::VitePressTheme::LastUpdated.source_file_time(document.site, document.path)
|
|
131
173
|
document.data['last_updated_at'] = updated_at if updated_at
|
|
132
174
|
end
|
|
133
175
|
|
|
134
|
-
Jekyll::Hooks.register :pages, :pre_render do |page|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
theme_config['copy_page'].is_a?(Hash) &&
|
|
138
|
-
theme_config['copy_page']['enabled'] == false
|
|
139
|
-
|
|
140
|
-
unless copy_page_disabled
|
|
141
|
-
page_theme = page.data['jekyll_vitepress']
|
|
142
|
-
copy_page_disabled = page_theme == false || (page_theme.is_a?(Hash) && page_theme['copy_page'] == false)
|
|
176
|
+
Jekyll::Hooks.register :pages, :pre_render do |page, payload|
|
|
177
|
+
if Jekyll::VitePressTheme::CopyPage.enabled?(page)
|
|
178
|
+
page.data['_raw_markdown'] = Jekyll::VitePressTheme::CopyPage.resolved_markdown(page, payload)
|
|
143
179
|
end
|
|
144
180
|
|
|
145
|
-
page.data['_raw_markdown'] = page.content unless copy_page_disabled
|
|
146
|
-
|
|
147
181
|
next if page.data.key?('last_updated_at')
|
|
148
182
|
|
|
149
183
|
updated_at = Jekyll::VitePressTheme::LastUpdated.source_file_time(page.site, page.path)
|
|
@@ -171,7 +205,7 @@ Jekyll::Hooks.register :site, :post_write do |site|
|
|
|
171
205
|
md_path = '/index.md' if item.url == '/'
|
|
172
206
|
|
|
173
207
|
title = item.data['title']
|
|
174
|
-
body = if title && !title.empty? && !
|
|
208
|
+
body = if title && !title.empty? && !Jekyll::VitePressTheme::CopyPage.leading_h1?(raw)
|
|
175
209
|
"# #{title}\n\n#{raw}"
|
|
176
210
|
else
|
|
177
211
|
raw
|