Skip to content

Commit

Permalink
Upgrade hugo version, fix the js rendering problem in the updated ver…
Browse files Browse the repository at this point in the history
…sion of hugo and update the css style

Signed-off-by: JesseStutler <chenzicong4@huawei.com>
  • Loading branch information
JesseStutler committed Dec 31, 2024
1 parent 5f6dd4f commit 1858971
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 31 deletions.
13 changes: 9 additions & 4 deletions config/_default/languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,28 @@
identifier = "concepts"

[[zh.menu.docs]]
name = "生态"
name = "关键特性"
weight = 4
identifier = "features"

[[zh.menu.docs]]
name = "生态"
weight = 5
identifier = "zoology"

[[zh.menu.docs]]
name = "Scheduler"
weight = 5
weight = 6
identifier = "scheduler"

[[zh.menu.docs]]
name = "CLI"
weight = 6
weight = 7
identifier = "cli"

[[zh.menu.docs]]
name = "贡献"
weight = 7
weight = 8
identifier = "contribution"


Expand Down
13 changes: 9 additions & 4 deletions config/_default/menus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,28 @@
identifier = "concepts"

[[docs]]
name = "Ecosystem"
name = "Key Features"
weight = 4
identifier = "features"

[[docs]]
name = "Ecosystem"
weight = 5
identifier = "ecosystem"

[[docs]]
name = "Scheduler"
weight = 5
weight = 6
identifier = "scheduler"

[[docs]]
name = "CLI"
weight = 6
weight = 7
identifier = "cli"

[[docs]]
name = "Contribution"
weight = 7
weight = 8
identifier = "contribution"


Expand Down
8 changes: 4 additions & 4 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ publish = "public"
command = "HUGO_BASEURL=$URL hugo"

[context.production.environment]
HUGO_VERSION = "0.57.2"
HUGO_VERSION = "0.79.1"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"

[context.split1]
command = "hugo --enableGitInfo"

[context.split1.environment]
HUGO_VERSION = "0.57.2"
HUGO_VERSION = "0.79.1"
HUGO_ENV = "production"

[context.deploy-preview]
command = "hugo --buildFuture -b $DEPLOY_PRIME_URL"

[context.deploy-preview.environment]
HUGO_VERSION = "0.57.2"
HUGO_VERSION = "0.79.1"

[context.branch-deploy]
command = "hugo -b $DEPLOY_PRIME_URL"

[context.branch-deploy.environment]
HUGO_VERSION = "0.57.2"
HUGO_VERSION = "0.79.1"

[context.next.environment]
HUGO_ENABLEGITINFO = "true"
40 changes: 32 additions & 8 deletions themes/academic/assets/js/academic.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,28 @@
if ($('body').hasClass('dark')) {
$('body').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 500);
$('body').removeClass('dark');
$('link[title=hl-light]')[0].disabled = false;
$('link[title=hl-dark]')[0].disabled = true;
let link = document.querySelector('link[title=hl-light]');
if (link) {
link.disabled = false;
}
let linkDark = document.querySelector('link[title=hl-dark]');
if (linkDark) {
linkDark.disabled = true;
}
$('.js-dark-toggle i').removeClass('fa-sun');
$('.js-dark-toggle i').addClass('fa-moon');
localStorage.setItem('dark_mode', '0');
} else {
$('body').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 500);
$('body').addClass('dark');
$('link[title=hl-light]')[0].disabled = true;
$('link[title=hl-dark]')[0].disabled = false;
let link = document.querySelector('link[title=hl-light]');
if (link) {
link.disabled = true;
}
let linkDark = document.querySelector('link[title=hl-dark]');
if (linkDark) {
linkDark.disabled = false;
}
$('.js-dark-toggle i').removeClass('fa-moon');
$('.js-dark-toggle i').addClass('fa-sun');
localStorage.setItem('dark_mode', '1');
Expand All @@ -339,14 +351,26 @@
let dark_mode = parseInt(localStorage.getItem('dark_mode') || default_mode);
if (dark_mode) {
$('body').addClass('dark');
$('link[title=hl-light]')[0].disabled = true;
$('link[title=hl-dark]')[0].disabled = false;
let link = document.querySelector('link[title=hl-light]');
if (link) {
link.disabled = false;
}
let linkDark = document.querySelector('link[title=hl-dark]');
if (linkDark) {
linkDark.disabled = true;
}
$('.js-dark-toggle i').removeClass('fa-moon');
$('.js-dark-toggle i').addClass('fa-sun');
} else {
$('body').removeClass('dark');
$('link[title=hl-light]')[0].disabled = false;
$('link[title=hl-dark]')[0].disabled = true;
let link = document.querySelector('link[title=hl-light]');
if (link) {
link.disabled = false;
}
let linkDark = document.querySelector('link[title=hl-dark]');
if (linkDark) {
linkDark.disabled = true;
}
$('.js-dark-toggle i').removeClass('fa-sun');
$('.js-dark-toggle i').addClass('fa-moon');
}
Expand Down
66 changes: 55 additions & 11 deletions themes/academic/layouts/partials/css/academic.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,15 @@ h1 {
font-size: 2.25rem;
}
h2 {
font-weight: 700;
margin-top: 1rem;
font-size: 1.5rem;
}
h3 {
font-weight: 700;
margin-top: 1.5rem;
font-size: 1.25rem;
}
h4, h5, h6 {
font-weight: 700;
margin-top: 1rem;
font-size: 1rem;
}
Expand Down Expand Up @@ -174,22 +173,67 @@ figcaption h4 {

pre,
code {
font-family: '{{ .Get "mono_font" }}', monospace;
color: #c7254e;
background-color: #f9f2f4;
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
font-size: 0.85rem;
}

pre {
margin: 0 0 1rem 0;
background-color: rgb(248, 248, 248); /* Match default highlight theme. */
border-color: rgb(248, 248, 248);
font-size: 0.7rem;
border-radius: 4px;
position: relative; /* 为复制按钮定位做准备 */
margin: 0 0 1.5rem 0;
padding: 1rem;
background-color: #f8f9fa;
border: 1px solid #eee;
border-radius: 6px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

pre code {
white-space: pre; /* Override Bootstrap to preserve line breaks in code. */
white-space: pre;
overflow-x: auto;
display: block;
padding: 0;
color: #24292e;
background-color: transparent;
}

pre::before {
content: attr(data-lang);
display: block;
background: #e9ecef;
color: #666;
font-size: 0.75rem;
padding: 0.2em 0.5em;
border-radius: 3px 3px 0 0;
margin: -1rem -1rem 1rem -1rem;
border-bottom: 1px solid #eee;
}

.code-copy-btn {
position: absolute;
right: 0.5rem;
top: 0.5rem;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
color: #666;
background: #fff;
border: 1px solid #eee;
border-radius: 4px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s;
}

pre:hover .code-copy-btn {
opacity: 1;
}

.code-copy-btn:hover {
background: #f8f9fa;
border-color: #ddd;
}

.code-copy-btn:active {
background: #eee;
}

hr {
Expand Down
48 changes: 48 additions & 0 deletions themes/academic/layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,53 @@
{{ $js_bundle := $js_bundle | resources.Concat "js/academic-bundle-pre.js" | minify }}
{{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat "js/academic.min.js" | fingerprint "md5" }}
<script src="{{ $js_bundle.RelPermalink }}"></script>

<script>
(function() {
// Add copy button to all code blocks
var pres = document.getElementsByTagName("pre");
for (var i = 0; i < pres.length; i++) {
var pre = pres[i];
if (!pre.querySelector('.code-copy-btn')) { // Avoid duplicate buttons
var btn = document.createElement("button");
btn.className = "code-copy-btn";
btn.textContent = "Copy";

btn.addEventListener('click', function() {
var code = this.parentElement.querySelector("code");
var text = code.textContent || code.innerText;

// Create temporary textarea for copying
var textarea = document.createElement("textarea");
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();

try {
var successful = document.execCommand('copy');
if (successful) {
this.textContent = "Copied!";
var self = this;
setTimeout(function() {
self.textContent = "Copy";
}, 1500);
} else {
this.textContent = "Failed";
}
} catch (err) {
console.error('Copy failed:', err);
this.textContent = "Failed";
}

document.body.removeChild(textarea);
});

pre.appendChild(btn);
}
}
})();
</script>
</body>
</html>

0 comments on commit 1858971

Please sign in to comment.