Skip to content

Commit 3f2ba3d

Browse files
author
tkokhing
committed
redefined TABLE styling, implement adaptive_fs_XX and loadPost for MD format
1 parent 44f21dc commit 3f2ba3d

5 files changed

Lines changed: 71 additions & 21 deletions

File tree

src/app/_components/main_frame/subpage-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const SubpageHeader = () => {
4545
return (
4646
<div className="sticky top-0 z-30 bg-slate-50 dark:bg-slate-900">
4747
<Container>
48-
<h2 className="uppercase text-1xl md:text-2xl font-light tracking-tight md:tracking-tighter leading-tight py-4 flex items-center">
48+
<h2 className="uppercase text-adaptive_fs_sm md:text-adaptive_fs_xs font-light tracking-tight md:tracking-tighter leading-tight py-1 flex items-center">
4949
<div className="truncate">{generateBreadcrumbs()}</div>
5050
</h2>
5151
<div className="h-1 bg-sky-500 transition-all" style={{ width: `${scroll}%` }} />

src/app/_components/preference/toggle-frame-button.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export function ToggleAllButton() {
1111
if (!ctx) return null;
1212

1313
return (
14-
<div className="sticky top-[4.5rem] z-20">
15-
<div className="flex gap-2 px-4 py-2 justify-end">
14+
<div className="sticky top-[1.8rem] md:top-[1.5rem] z-20">
15+
<div className="text-adaptive_fs_xs flex gap-1 px-4 py-2 justify-end">
1616
<button
1717
disabled={state === "open"}
1818
onClick={() => {
1919
ctx.openAll();
2020
setState("open");
2121
}}
22-
className={`px-3 py-1 rounded text-xs transition ${
22+
className={`px-3 py-1 rounded transition ${
2323
state === "open"
2424
? "bg-gray-700 dark:bg-gray-600 text-tkokhing-blue cursor-default"
2525
: "bg-gray-200 hover:bg-gray-500 dark:text-tkokhing-blue hover:text-tkokhing-dark hover:dark:text-tkokhing-dark"
@@ -34,7 +34,7 @@ export function ToggleAllButton() {
3434
ctx.closeAll();
3535
setState("closed");
3636
}}
37-
className={`px-3 py-1 rounded text-xs transition ${
37+
className={`px-3 py-1 rounded transition ${
3838
state === "closed"
3939
? "bg-gray-700 dark:bg-gray-600 text-tkokhing-blue cursor-default"
4040
: "bg-gray-200 hover:bg-gray-500 dark:text-tkokhing-blue hover:text-tkokhing-dark hover:dark:text-tkokhing-dark"

src/app/heptagoning/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Container from "@/app/_components/preference/container";
2-
import { getAllPosts } from "@/lib/share/api";
2+
import { getAllPosts, loadPost } from "@/lib/share/api";
33
import { HeroPost } from "@/app/_components/post_gen/hero-post";
44
import { MoreStories } from "@/app/_components/post_gen/more-stories";
5+
import { PostBody } from "../_components/post_gen/post-body";
56

67
export default function Index() {
8+
9+
const readmeHeptagoning = loadPost("README.md","_heptagoning")
710
const allPosts = getAllPosts("_heptagoning/_kill-chain");
811

912
const filteredPosts = allPosts.filter(
@@ -14,6 +17,8 @@ export default function Index() {
1417
return (
1518
<main>
1619
<Container>
20+
<PostBody content={readmeHeptagoning} />
21+
<br />
1722
<HeroPost
1823
title={heroPost.title}
1924
coverImage={heroPost.coverImage}

src/lib/share/api.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,50 @@ function useBasePath(): string {
88
return process.env.GITHUB_ACTIONS ? REPO_NAME : '';
99
}
1010

11-
function postsDirectory(mdx_folder: string): string{
12-
fs.readdir((join(process.cwd(), mdx_folder)), (err) => {
11+
function postsDirectory(post_folder: string): string{
12+
fs.readdir((join(process.cwd(), post_folder)), (err) => {
1313
if (err) {
1414
console.error('Error reading directory:', err);
1515
}
1616
})
17-
return join(process.cwd(), mdx_folder);
17+
return join(process.cwd(), post_folder);
1818
}
1919

20-
function getPostSlugs(mdx_folder: string) {
20+
// dual usage, call it directly to load MD format
21+
export function loadPost(slug: string, post_folder: string) {
22+
const ext = slug.endsWith(".mdx")
23+
? ".mdx"
24+
: slug.endsWith(".md")
25+
? ".md"
26+
: ".mdx"; // default fallback
27+
28+
const realSlug = slug.replace(/\.mdx?$/, "").replace(/\.md$/, "");
29+
const fullPath = join(postsDirectory(post_folder), `${realSlug}${ext}`);
30+
return fs.readFileSync(fullPath, "utf-8");
31+
}
32+
33+
function getPostSlugs(post_folder: string) {
2134
return fs
22-
.readdirSync(postsDirectory(mdx_folder), { withFileTypes: true })
35+
.readdirSync(postsDirectory(post_folder), { withFileTypes: true })
2336
.filter(entry => entry.isFile() && entry.name.endsWith(".mdx"))
2437
.map(entry => entry.name);
2538
}
2639

27-
export function getPostBySlug(slug: string, mdx_folder: string) {
28-
const realSlug = slug.replace(/\.mdx?$/, "");
29-
const fullPath = join(postsDirectory(mdx_folder), `${realSlug}.mdx`);
30-
31-
const fileContents = fs.readFileSync(fullPath, "utf8");
40+
export function getPostBySlug(slug: string, post_folder: string) {
41+
const fileContents = loadPost(slug,post_folder);
3242
const { data, content } = matter(fileContents);
33-
3443
const BASE_PATH = useBasePath();
3544

3645
// Update URLs based on the environment
3746
data.coverImage = data.coverImage.startsWith(BASE_PATH) ? data.coverImage : `${BASE_PATH}${data.coverImage}`;
3847
data.author.picture = data.author.picture.startsWith(BASE_PATH) ? data.author.picture : `${BASE_PATH}${data.author.picture}`;
3948
data.ogImage.url = data.ogImage.url.startsWith(BASE_PATH) ? data.ogImage.url : `${BASE_PATH}${data.ogImage.url}`;
4049

41-
return { ...data, slug: realSlug, content } as Post;
50+
return { ...data, slug: slug.replace(/\.mdx?$/, ""), content } as Post;
4251
}
4352

44-
export function getAllPosts(mdx_folder: string): Post[] {
45-
const slugs = getPostSlugs(mdx_folder);
46-
const posts = slugs.map(slug => getPostBySlug(slug, mdx_folder));
53+
export function getAllPosts(post_folder: string): Post[] {
54+
const slugs = getPostSlugs(post_folder);
55+
const posts = slugs.map(slug => getPostBySlug(slug, post_folder));
4756
return posts.sort((post1, post2) => (post1.date > post2.date ? -1 : 1));
4857
}

src/styles/blog.module.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
color: #1e3a8a;
2424
}
2525

26+
.prose {
27+
max-width: 100%;
28+
}
29+
2630
/* for < pre > < code > block codes render IP and timming suffix */
2731
.prose pre{
2832
@apply bg-[#24292E] rounded-lg p-4;
@@ -42,4 +46,36 @@
4246
@apply text-tkokhing-dark;
4347
padding: 0.15em 0.4em;
4448
border-radius: 0.375rem;
49+
}
50+
51+
/* Prevent tables from breaking container */
52+
.prose table {
53+
display: block;
54+
margin-left: auto;
55+
table-layout: auto;
56+
margin-right: auto;
57+
max-width: 100%;
58+
overflow-x: auto;
59+
white-space: nowrap;
60+
background: rgba(0,0,0,0.13);
61+
border-radius: 0.375rem;
62+
padding: 0.5rem;
63+
}
64+
65+
.dark .prose table {
66+
background: rgba(255,255,255,0.24);
67+
}
68+
69+
/* Chrome / Edge / Safari */
70+
.prose table::-webkit-scrollbar {
71+
height: 6px;
72+
}
73+
74+
.prose table::-webkit-scrollbar-track {
75+
background: transparent;
76+
}
77+
78+
.prose table::-webkit-scrollbar-thumb {
79+
background: rgba(120,120,120,0.5);
80+
border-radius: 9999px;
4581
}

0 commit comments

Comments
 (0)