Skip to content

Commit dcb6a10

Browse files
update
1 parent 4329b4e commit dcb6a10

File tree

3 files changed

+63
-48
lines changed

3 files changed

+63
-48
lines changed

assets/css/style.css

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
*{
2-
margin: 0;
3-
padding: 0;
4-
box-sizing: border-box;
5-
}
6-
7-
body{
8-
font-family:'Inter',sans-serif;
9-
background:#0f1720;
10-
color:#e6eef8;
11-
line-height:1.6;
12-
}
13-
14-
.wrap{
15-
max-width:1000px;
16-
margin:32px auto;
17-
padding:20px;
18-
}
19-
20-
h1{
21-
text-align:center;
22-
margin-bottom:32px;
23-
}
24-
25-
.articles-grid{
26-
display:grid;
27-
grid-template-columns:repeat(auto-fill,minmax(280px,1fr));
28-
gap:20px;
2+
margin:0;
3+
padding:0;
4+
box-sizing:border-box;
295
}
306

7+
body{margin:0;font-family:'Inter',sans-serif;background:#0f1720;color:#e6eef8;line-height:1.6;}
8+
.wrap{max-width:1000px;margin:32px auto;padding:20px;}
9+
h1{text-align:center;margin-bottom:32px;}
10+
.articles-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:20px;}
3111
.article-card{background:rgba(255,255,255,0.02);border-radius:14px;padding:20px;border:1px solid rgba(255,255,255,0.03);cursor:pointer;transition:0.2s;}
3212
.article-card:hover{transform:translateY(-4px);box-shadow:0 12px 24px rgba(0,0,0,0.3);}
3313
.article-card h2{margin-top:0;color:#7c5cff;}

assets/js/main.js

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --- GitHub Config ---
22
const GITHUB_USER = 'codebysushil';
3-
const GITHUB_REPO = "codebysushil.github.io";
3+
const GITHUB_REPO = 'codebysushil.github.io';
44
const ARTICLES_PATH = 'articles';
55
const BRANCH = 'main';
66

@@ -21,13 +21,6 @@ function parseFrontMatter(md){
2121
}
2222
function formatDate(iso){try{const d=new Date(iso);return isNaN(d)?iso:d.toLocaleDateString(undefined,{year:'numeric',month:'short',day:'numeric'});}catch(e){return iso}}
2323
function estimateReadTime(text){const words=text.trim().split(/\s+/).length;return Math.max(1,Math.round(words/200))+' min read'}
24-
async function incAndGetViews(key){
25-
try{
26-
const res=await fetch(`https://api.countapi.xyz/hit/${GITHUB_USER}-${GITHUB_REPO}/${key}`);
27-
const json=await res.json();
28-
return json.value||0;
29-
}catch(e){return '—'}
30-
}
3124

3225
// --- DOM Elements ---
3326
const grid=document.getElementById('articles-grid');
@@ -85,7 +78,6 @@ let currentIndex=0; // current article in modal
8578
<div class="meta">By ${article.author} | ${article.date}</div>
8679
<div class="tags">${article.tags}</div>
8780
`;
88-
8981
card.addEventListener('click',()=>openModal(articlesData.indexOf(article)));
9082
grid.appendChild(card);
9183

@@ -96,18 +88,49 @@ let currentIndex=0; // current article in modal
9688

9789
// --- Modal functions ---
9890
async function openModal(index){
99-
currentIndex=index;
100-
const article=articlesData[index];
101-
modalTitle.textContent=article.title;
102-
modalAuthor.textContent='By '+article.author;
103-
modalDate.textContent=article.date;
104-
modalReadtime.textContent=estimateReadTime(article.content);
105-
modalTags.textContent=article.tags;
106-
if(article.cover){modalCover.src=article.cover; modalCover.style.display='block';} else modalCover.style.display='none';
107-
articleContent.innerHTML=marked.parse(article.content);
91+
currentIndex = index;
92+
const article = articlesData[index];
93+
94+
// --- Update modal content ---
95+
modalTitle.textContent = article.title;
96+
modalAuthor.textContent = 'By ' + article.author;
97+
modalDate.textContent = article.date;
98+
modalReadtime.textContent = estimateReadTime(article.content);
99+
modalTags.textContent = article.tags;
100+
101+
if(article.cover){
102+
modalCover.src = article.cover;
103+
modalCover.style.display = 'block';
104+
} else {
105+
modalCover.style.display = 'none';
106+
}
107+
108+
articleContent.innerHTML = marked.parse(article.content);
108109
Prism.highlightAll();
109-
modalViews.textContent='Views: ' + await incAndGetViews(article.fileName.replace(/\.[^/.]+$/,""));
110-
modal.style.display='flex';
110+
111+
// --- GA4 Event Tracking ---
112+
if (typeof gtag === 'function') {
113+
gtag('event', 'view_article', {
114+
article_name: article.title,
115+
article_file: article.fileName
116+
});
117+
}
118+
119+
// --- Local view counter ---
120+
const storageKey = 'views_' + article.fileName;
121+
let views = parseInt(localStorage.getItem(storageKey)) || 0;
122+
views++;
123+
localStorage.setItem(storageKey, views);
124+
modalViews.textContent = 'Views (you): ' + views;
125+
126+
// --- Update page title & meta description ---
127+
document.title = article.title + " | Code By Sushil";
128+
const metaDesc = document.querySelector('meta[name="description"]');
129+
if(metaDesc){
130+
metaDesc.setAttribute('content', article.description || article.title);
131+
}
132+
133+
modal.style.display = 'flex';
111134
}
112135

113136
// Next / Previous

index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<title>Code By Sushil | Articles</title>
7+
<meta name="description" content="Code By Sushil or Code With Sushil aka Sushil Kumar">
78

9+
<!-- Google Fonts & Prism -->
810
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
911
<link href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism.min.css" rel="stylesheet">
12+
13+
<!-- GA4 -->
14+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
15+
<script>
16+
window.dataLayer = window.dataLayer || [];
17+
function gtag(){dataLayer.push(arguments);}
18+
gtag('js', new Date());
19+
gtag('config', 'G-XXXXXXXXXX'); // <-- Replace with your GA4 Measurement ID
20+
</script>
1021
<link rel="stylesheet" href="./assets/css/style.css"/>
1122
</head>
1223
<body>
13-
<div class="wrap">
24+
25+
<div class="wrap">
1426
<h1>Articles</h1>
1527
<div class="articles-grid" id="articles-grid"></div>
1628
</div>

0 commit comments

Comments
 (0)