Skip to content

Commit d1d1cc3

Browse files
committed
new theme with sidebar changed
1 parent 52d6141 commit d1d1cc3

File tree

223 files changed

+10746
-1336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+10746
-1336
lines changed

assets/images/404.png

108 KB
Loading

assets/images/404.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/images/default-avatar.png

46.5 KB
Loading

assets/images/default-hero.jpg

69.4 KB
Loading

assets/images/favicon.png

13.3 KB
Loading

assets/images/hugo-logo.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/images/inverted-logo.png

13.3 KB
Loading

assets/images/main-logo.png

5.5 KB
Loading

assets/images/theme-logo.png

13.3 KB
Loading
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ function addCopyButtonToCodeBlocks() {
3737

3838

3939
// For each code block, add a copy button inside a header
40-
4140
codeBlocks.forEach((codeBlock) => {
4241

4342
// Get the background color of the code block
44-
4543
const computedStyle = window.getComputedStyle(codeBlock);
4644
const backgroundColor = computedStyle.backgroundColor;
4745

@@ -169,35 +167,36 @@ function addCopyButtonToCodeBlocks() {
169167
// Call the function to add copy buttons to code blocks
170168
document.addEventListener("DOMContentLoaded", addCopyButtonToCodeBlocks);
171169

172-
function addCopyButtons(clipboard) {
173-
document.querySelectorAll('pre > code').forEach(function (codeBlock) {
174-
var button = document.createElement('button');
175-
button.className = 'copy-code-button';
176-
button.type = 'button';
177-
button.innerText = 'Copy';
170+
// function addCopyButtons(clipboard) {
171+
// document.querySelectorAll('pre > code').forEach(function (codeBlock) {
172+
// var button = document.createElement('button');
173+
// button.className = 'copy-code-button';
174+
// button.type = 'button';
175+
// button.innerText = 'Copy';
178176

179-
button.addEventListener('click', function () {
180-
clipboard.writeText(codeBlock.innerText).then(function () {
181-
/* Chrome doesn't seem to blur automatically,
182-
leaving the button in a focused state. */
183-
button.blur();
177+
// button.addEventListener('click', function () {
178+
// clipboard.writeText(codeBlock.innerText).then(function () {
179+
// /* Chrome doesn't seem to blur automatically,
180+
// leaving the button in a focused state. */
181+
// button.blur();
184182

185-
button.innerText = 'Copied!';
183+
// button.innerText = 'Copied!';
186184

187-
setTimeout(function () {
188-
button.innerText = 'Copy';
189-
}, 2000);
190-
}, function (error) {
191-
button.innerText = 'Error';
192-
});
193-
});
185+
// setTimeout(function () {
186+
// button.innerText = 'Copy';
187+
// }, 2000);
188+
// }, function (error) {
189+
// button.innerText = 'Error';
190+
// });
191+
// });
192+
193+
// var pre = codeBlock.parentNode;
194+
// if (pre.parentNode.classList.contains('highlight')) {
195+
// var highlight = pre.parentNode;
196+
// highlight.parentNode.insertBefore(button, highlight);
197+
// } else {
198+
// pre.parentNode.insertBefore(button, pre);
199+
// }
200+
// });
201+
// }
194202

195-
var pre = codeBlock.parentNode;
196-
if (pre.parentNode.classList.contains('highlight')) {
197-
var highlight = pre.parentNode;
198-
highlight.parentNode.insertBefore(button, highlight);
199-
} else {
200-
pre.parentNode.insertBefore(button, pre);
201-
}
202-
});
203-
}

assets/jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"baseUrl": ".",
44
"paths": {
55
"*": [
6-
"..\\..\\..\\AppData\\Local\\hugo_cache\\modules\\filecache\\modules\\pkg\\mod\\github.com\\hugo-toha\\toha\\v4@v4.5.1-0.20240601184722-8599c634e39f\\assets\\*"
6+
"*"
77
]
88
}
99
}

assets/scripts/application.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'popper.js'
2+
import 'bootstrap'
3+
import '@fortawesome/fontawesome-free/js/all'
4+
import feather from 'feather-icons'
5+
6+
import './core'
7+
import './features'
8+
import './sections'
9+
import './pages'
10+
11+
feather.replace();

assets/scripts/core/device.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
let deviceState = {
2+
isMobile: false,
3+
isTablet: false,
4+
isLaptop: false
5+
}
6+
7+
function detectDeviceState () {
8+
if (window.innerWidth <= 425) {
9+
deviceState = {
10+
isMobile: true,
11+
isTablet: false,
12+
isLaptop: false
13+
}
14+
} else if (window.innerWidth <= 768) {
15+
deviceState = {
16+
isMobile: false,
17+
isTablet: true,
18+
isLaptop: false
19+
}
20+
} else {
21+
deviceState = {
22+
isMobile: false,
23+
isTablet: false,
24+
isLaptop: true
25+
}
26+
}
27+
}
28+
29+
detectDeviceState()
30+
window.addEventListener('resize', detectDeviceState)
31+
32+
// returns a copy of the device state
33+
// so other parts of code can't override this.
34+
export function getDeviceState () {
35+
return { ...deviceState }
36+
}

assets/scripts/core/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './device'
2+
export * from './insertScript'

assets/scripts/core/insertScript.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const insertScript = (id, src, onload) => {
2+
// script is already inserted, do nothing
3+
if (document.getElementById(id)) return
4+
5+
// insert script
6+
const firstScriptTag = document.getElementsByTagName('script')[0]
7+
const scriptTag = document.createElement('script')
8+
scriptTag.id = id
9+
scriptTag.onload = onload
10+
scriptTag.src = src
11+
scriptTag.defer = true
12+
scriptTag.async = true
13+
firstScriptTag.parentNode.insertBefore(scriptTag, firstScriptTag)
14+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const PERSISTENCE_KEY = 'darkmode:color-scheme'
2+
3+
window.addEventListener('load', async () => {
4+
const menu = document.getElementById('themeMenu')
5+
const $icon = document.getElementById('navbar-theme-icon-svg')
6+
if (menu == null || $icon == null) return
7+
8+
const btns = menu.getElementsByTagName('a')
9+
const iconMap = Array.from(btns).reduce((map, btn) => {
10+
const $img = btn.getElementsByTagName('img')[0]
11+
map[btn.dataset.scheme] = $img.src
12+
return map
13+
}, {})
14+
15+
16+
function loadScheme() {
17+
return localStorage.getItem(PERSISTENCE_KEY) || "system"
18+
}
19+
20+
function saveScheme(scheme) {
21+
localStorage.setItem(PERSISTENCE_KEY, scheme)
22+
}
23+
24+
function getPreferredColorScheme() {
25+
const isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
26+
return isDarkMode ? "dark" : "light";
27+
}
28+
29+
function setScheme(newScheme) {
30+
let theme = newScheme
31+
if (newScheme === 'system') {
32+
theme = getPreferredColorScheme()
33+
}
34+
// set data-theme attribute on html tag
35+
document.querySelector("html").dataset.theme = theme;
36+
37+
// update icon
38+
$icon.src = iconMap[newScheme]
39+
40+
// save preference to local storage
41+
saveScheme(newScheme)
42+
43+
setImages(theme)
44+
}
45+
46+
setScheme(loadScheme())
47+
48+
Array.from(menu.getElementsByTagName('a')).forEach((btn) => {
49+
btn.addEventListener('click', () => {
50+
const { scheme } = btn.dataset
51+
setScheme(scheme)
52+
})
53+
})
54+
})
55+
56+
function setImages(newScheme) {
57+
const els = Array.from(document.getElementsByClassName('logo-holder'));
58+
for (const el of els) {
59+
const light = el.querySelector('.light-logo');
60+
const dark = el.querySelector('.dark-logo');
61+
if (newScheme === "dark" && dark !== null) {
62+
if (light !== null) light.style.display = 'none'
63+
dark.style.display = 'inline'
64+
}
65+
else {
66+
if (light !== null) light.style.display = 'inline'
67+
if (dark !== null) dark.style.display = 'none'
68+
}
69+
}
70+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import { insertScript } from '../../core'
2+
3+
const PDFJS_BUNDLE = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.0.279/build/pdf.min.js'
4+
const WORKER_BUNDLE = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.0.279/build/pdf.worker.min.js'
5+
6+
class PDFViewer {
7+
constructor (el) {
8+
const {
9+
url,
10+
hidePaginator,
11+
hideLoader,
12+
scale,
13+
pageNum
14+
} = el.dataset
15+
16+
if (url == null) {
17+
throw new Error('Cannot load PDF! Attribute `data-url` is not set.')
18+
}
19+
20+
// props
21+
this.url = url
22+
this.hidePaginator = hidePaginator !== 'false'
23+
this.hideLoader = hideLoader !== 'false'
24+
this.scale = scale || 3
25+
26+
// initial state
27+
this.pageNum = parseInt(pageNum, 10) || 1
28+
this.loaded = false
29+
this.pageRendering = false
30+
this.pageNumPending = null
31+
32+
// DOM elements
33+
this.canvas = el.getElementsByClassName('pdf-canvas')[0]
34+
if (this.canvas == null) {
35+
throw new Error('canvas element not found!')
36+
};
37+
this.paginator = el.getElementsByClassName('paginator')[0]
38+
this.loadingWrapper = el.getElementsByClassName('loading-wrapper')[0]
39+
this.next = el.getElementsByClassName('next')[0]
40+
this.prev = el.getElementsByClassName('prev')[0]
41+
this.curPage = el.getElementsByClassName('page-num')[0]
42+
this.pageCount = el.getElementsByClassName('page-count')[0]
43+
44+
// context
45+
this.ctx = this.canvas.getContext('2d')
46+
47+
// events
48+
this.next.addEventListener('click', this.handleNextPage.bind(this))
49+
this.prev.addEventListener('click', this.handlePrevPage.bind(this))
50+
51+
this.showPaginator()
52+
this.showLoader()
53+
this.loadPDF()
54+
}
55+
56+
/**
57+
* If we haven't disabled the loader, show loader and hide canvas
58+
*/
59+
showLoader () {
60+
if (this.hideLoader) return
61+
this.loadingWrapper.style.display = 'flex'
62+
this.canvas.style.display = 'none'
63+
}
64+
65+
/**
66+
* If we haven't disabled the paginator, show paginator
67+
*/
68+
showPaginator () {
69+
if (this.hidePaginator) return
70+
this.paginator.style.display = 'block'
71+
}
72+
73+
/**
74+
* Hides loader and shows canvas
75+
*/
76+
showContent () {
77+
this.loadingWrapper.style.display = 'none'
78+
this.canvas.style.display = 'block'
79+
}
80+
81+
/**
82+
* Asynchronously downloads PDF.
83+
*/
84+
async loadPDF () {
85+
this.pdfDoc = await window.pdfjsLib.getDocument(this.url).promise
86+
87+
this.pageCount.textContent = this.pdfDoc.numPages
88+
89+
// If the user passed in a number that is out of range, render the last page.
90+
if (this.pageNum > this.pdfDoc.numPages) {
91+
this.pageNum = this.pdfDoc.numPages
92+
}
93+
94+
this.renderPage(this.pageNum)
95+
}
96+
97+
/**
98+
* Get page info from document, resize canvas accordingly, and render page.
99+
* @param num Page number.
100+
*/
101+
async renderPage (num) {
102+
this.pageRendering = true
103+
104+
const page = await this.pdfDoc.getPage(num)
105+
const viewport = page.getViewport({ scale: this.scale })
106+
this.canvas.height = viewport.height
107+
this.canvas.width = viewport.width
108+
109+
// Wait for rendering to finish
110+
await page.render({
111+
canvasContext: this.ctx,
112+
viewport
113+
}).promise
114+
115+
this.pageRendering = false
116+
this.showContent()
117+
118+
if (this.pageNumPending !== null) {
119+
// New page rendering is pending
120+
this.renderPage(this.pageNumPending)
121+
this.pageNumPending = null
122+
}
123+
// Update page counters
124+
this.curPage.textContent = num
125+
}
126+
127+
/**
128+
* If another page rendering in progress, waits until the rendering is
129+
* finished. Otherwise, executes rendering immediately.
130+
*/
131+
queueRenderPage (num) {
132+
if (this.pageRendering) {
133+
this.pageNumPending = num
134+
} else {
135+
this.renderPage(num)
136+
}
137+
}
138+
139+
/**
140+
* Displays previous page.
141+
*/
142+
handlePrevPage () {
143+
if (this.pageNum <= 1) {
144+
return
145+
}
146+
this.pageNum--
147+
this.queueRenderPage(this.pageNum)
148+
}
149+
150+
/**
151+
* Displays next page.
152+
*/
153+
handleNextPage () {
154+
if (this.pageNum >= this.pdfDoc.numPages) {
155+
return
156+
}
157+
this.pageNum++
158+
this.queueRenderPage(this.pageNum)
159+
}
160+
}
161+
162+
insertScript('pdfjs', PDFJS_BUNDLE, () => {
163+
window.pdfjsLib.GlobalWorkerOptions.workerSrc = WORKER_BUNDLE
164+
Array.from(document.getElementsByClassName('pdf-viewer')).forEach(el => new PDFViewer(el))
165+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (process.env.FEATURE_FLOWCHART_MERMAID === '1') {
2+
import('./mermaid')
3+
}

0 commit comments

Comments
 (0)