Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CaiJimmy/hugo-theme-stack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'assets/ts/main.ts')
-rw-r--r--assets/ts/main.ts69
1 files changed, 67 insertions, 2 deletions
diff --git a/assets/ts/main.ts b/assets/ts/main.ts
index 0668c7c..f3160ae 100644
--- a/assets/ts/main.ts
+++ b/assets/ts/main.ts
@@ -5,7 +5,8 @@
* @website: https://jimmycai.com
* @link: https://github.com/CaiJimmy/hugo-theme-stack
*/
-import StackCodeBlock from "ts/codeblock";
+import StackGallery from "ts/gallery";
+import { getColor } from 'ts/color';
import menu from 'ts/menu';
import createElement from 'ts/createElement';
import StackColorScheme from 'ts/colorScheme';
@@ -21,12 +22,76 @@ let Stack = {
const articleContent = document.querySelector('.article-content') as HTMLElement;
if (articleContent) {
+ new StackGallery(articleContent);
setupSmoothAnchors();
setupScrollspy();
}
+ /**
+ * Add linear gradient background to tile style article
+ */
+ const articleTile = document.querySelector('.article-list--tile');
+ if (articleTile) {
+ let observer = new IntersectionObserver(async (entries, observer) => {
+ entries.forEach(entry => {
+ if (!entry.isIntersecting) return;
+ observer.unobserve(entry.target);
+
+ const articles = entry.target.querySelectorAll('article.has-image');
+ articles.forEach(async articles => {
+ const image = articles.querySelector('img'),
+ imageURL = image.src,
+ key = image.getAttribute('data-key'),
+ hash = image.getAttribute('data-hash'),
+ articleDetails: HTMLDivElement = articles.querySelector('.article-details');
+
+ const colors = await getColor(key, hash, imageURL);
+
+ articleDetails.style.background = `
+ linear-gradient(0deg,
+ rgba(${colors.DarkMuted.rgb[0]}, ${colors.DarkMuted.rgb[1]}, ${colors.DarkMuted.rgb[2]}, 0.5) 0%,
+ rgba(${colors.Vibrant.rgb[0]}, ${colors.Vibrant.rgb[1]}, ${colors.Vibrant.rgb[2]}, 0.75) 100%)`;
+ })
+ })
+ });
+
+ observer.observe(articleTile)
+ }
+
+
+ /**
+ * Add copy button to code block
+ */
+ const highlights = document.querySelectorAll('.article-content div.highlight');
+ const copyText = `Copy`,
+ copiedText = `Copied!`;
+
+ highlights.forEach(highlight => {
+ const copyButton = document.createElement('button');
+ copyButton.innerHTML = copyText;
+ copyButton.classList.add('copyCodeButton');
+ highlight.appendChild(copyButton);
+
+ const codeBlock = highlight.querySelector('code[data-lang]');
+ if (!codeBlock) return;
+
+ copyButton.addEventListener('click', () => {
+ navigator.clipboard.writeText(codeBlock.textContent)
+ .then(() => {
+ copyButton.textContent = copiedText;
+
+ setTimeout(() => {
+ copyButton.textContent = copyText;
+ }, 1000);
+ })
+ .catch(err => {
+ alert(err)
+ console.log('Something went wrong', err);
+ });
+ });
+ });
+
new StackColorScheme(document.getElementById('dark-mode-toggle'));
- StackCodeBlock();
}
}