Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add work to github; created views.json to catch views; TODO: get vie… #579

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tags:
- Education
- Community
is_featured: true
views:
---

## Introduction
Expand Down
2 changes: 1 addition & 1 deletion src/data/blogs/combat-to-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tags:
- Veteran's Guide
- Personal Development
is_featured: true
views: 512
views:
---

## Introduction
Expand Down
4 changes: 2 additions & 2 deletions src/data/blogs/how-veterans-use-ai-at-vets-who-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ tags:
- GitHub Copilot
- Azure Open AI
- Coding Education
- Veterans in Tech
- Vets Who Code
is_featured: true
views:
views:

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tags:
- javascript
- typescript
is_featured: true
views: 12
views:
---

## Introduction
Expand Down
2 changes: 1 addition & 1 deletion src/data/blogs/post-bootcamp-tips-for-rookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tags:
- resume
- newbie
is_featured: true
views: 120
views:
---

Congratulations! You've just completed a coding bootcamp and are now ready to face the world of programming head-on. But what should you do next? Here are some tips to help you succeed in your new career.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tags:
- Career Change
- Tech Skills
is_featured: true
views: 250
views:
---

## Welcome Aboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tags:
- job
- newbie
is_featured: true
views: 215
views:
---

## Introduction
Expand Down
2 changes: 1 addition & 1 deletion src/data/courses/command-line.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": 1,
"title": "Command Line",
"thumbnail": {
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688176572/command-line_azvdf6.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688176572/command-line_azvdf6.jpg"
},
"published_at": "2020-12-01T00:00:00.000Z",
"category": "programming",
Expand Down
2 changes: 1 addition & 1 deletion src/data/courses/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": 2,
"title": "GitHub",
"thumbnail": {
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688176572/github_jk1wxq.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688176572/github_jk1wxq.jpg"
},
"published_at": "2018-02-01T00:00:00.000Z",
"category": "Programming",
Expand Down
2 changes: 1 addition & 1 deletion src/data/courses/html-and-css.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": 4,
"title": "Semantic HTML && CSS3",
"thumbnail": {
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688176572/html-css_fkwetk.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688176572/html-css_fkwetk.jpg"
},
"published_at": "2018-03-01T00:00:00.000Z",
"category": "Technology",
Expand Down
2 changes: 1 addition & 1 deletion src/data/courses/javascript-part-one.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": 5,
"title": "Javascript 101",
"thumbnail": {
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688176572/js-101_bwe5bt.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688176572/js-101_bwe5bt.jpg"
},
"published_at": "2018-04-01T00:00:00.000Z",
"category": "Programming",
Expand Down
2 changes: 1 addition & 1 deletion src/data/courses/javascript-part-two.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": 6,
"title": "Javascript 201",
"thumbnail": {
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688176572/js-201_oyauss.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688176572/js-201_oyauss.jpg"
},
"published_at": "2018-04-01T00:00:00.000Z",
"category": "Programming",
Expand Down
2 changes: 1 addition & 1 deletion src/data/courses/visual-studio-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": 3,
"title": "Visual Studio Code",
"thumbnail": {
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688176572/vsc_xiqqpc.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688176572/vsc_xiqqpc.jpg"
},
"published_at": "2018-01-01T00:00:00.000Z",
"category": "Business",
Expand Down
26 changes: 13 additions & 13 deletions src/data/homepages/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"images": [
{
"id":1,
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
}
],
"video": {
Expand All @@ -60,7 +60,7 @@
"id": 1,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1678667460/website-images/vetswhocode-remote.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1678667460/website-images/vetswhocode-remote.jpg"
}
],
"title": "Remote-First Learning",
Expand All @@ -72,7 +72,7 @@
"id": 2,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1678667458/website-images/vetswhocode-self-paced.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1678667458/website-images/vetswhocode-self-paced.jpg"
}
],
"title": "Develop Cutting-Edge Skills",
Expand All @@ -84,7 +84,7 @@
"id": 3,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1678667458/website-images/vetswhocode-learn-with-peers.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1678667458/website-images/vetswhocode-learn-with-peers.jpg"
}
],
"title": "A Lifelong Community of Support",
Expand Down Expand Up @@ -142,7 +142,7 @@
"images": [
{
"id": 1,
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1678667455/website-images/vetswhocode-about-us.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1678667455/website-images/vetswhocode-about-us.jpg"
}
],
"video": {
Expand Down Expand Up @@ -179,7 +179,7 @@
"description": "During my transition, I have signed up for and utilized services from over 14 different Non-Profits, Corporate, and State resources. I attended all three US Army military transition tracks (Business, Education, Career), been a part of a variety of technology training programs and transition programs. Of all of these programs, only three have made a significant contribution to my transition, and of these three organizations, only one has truly changed my life for the better. Vets Who Code delivered more value to me than 12 of the non-profits combined.",
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1656258222/Headshots/ozzie_zcaamv.png"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1656258222/Headshots/ozzie_zcaamv.png"
}
]
},
Expand All @@ -194,7 +194,7 @@
"description": "#VetsWhoCode's tenacious focus on language and computer science fundamentals over frameworks was invaluable in my career transition from being a Radiology Technician in the US Army to building cloud scale infrastructure at Microsoft. The coaching from the #VetsWhoCode’s talented and passionate mentor network proved to be a priceless asset even after graduating. Come ready to learn and you will succeed here.",
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1656258228/Headshots/jeff-martin_gufjmm.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1656258228/Headshots/jeff-martin_gufjmm.jpg"
}
]
}
Expand Down Expand Up @@ -230,47 +230,47 @@
"id": 1,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688306091/cloudflare-logo-black_ykp638.svg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688306091/cloudflare-logo-black_ykp638.svg"
}
]
},
{
"id": 2,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688306091/hashicorp-logo-black_to3p7b.svg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688306091/hashicorp-logo-black_to3p7b.svg"
}
]
},
{
"id": 3,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688306091/slack-logo-black_icrcmh.svg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688306091/slack-logo-black_icrcmh.svg"
}
]
},
{
"id": 4,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688306091/contentful-logo-black_e0qbr1.png"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688306091/contentful-logo-black_e0qbr1.png"
}
]
},
{
"id": 5,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688400679/femasters-logo-black_yzed8u.png"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688400679/femasters-logo-black_yzed8u.png"
}
]
},
{
"id": 6,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1688401001/adzuna-logo-black_vtjcr2.png"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1688401001/adzuna-logo-black_vtjcr2.png"
}
]
}
Expand Down
14 changes: 7 additions & 7 deletions src/data/innerpages/about-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"id": 1,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
}
],
"headings": [
Expand All @@ -32,7 +32,7 @@
"id": 2,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
}
],
"headings": [
Expand All @@ -56,7 +56,7 @@
"id": 3,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1710539370/vetswhocode-navyblue-banner.jpg"
}
],
"headings": [
Expand Down Expand Up @@ -89,7 +89,7 @@
"id": 1,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1627489542/speaking_e1fnh7.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1627489542/speaking_e1fnh7.jpg"
}
],
"headings": [
Expand All @@ -113,7 +113,7 @@
"id": 2,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1595194680/megan-and-daymond_ignjfa.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1595194680/megan-and-daymond_ignjfa.jpg"
}
],
"headings": [
Expand All @@ -137,7 +137,7 @@
"id": 3,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1656268447/this_is_us_b8p2xl.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1656268447/this_is_us_b8p2xl.jpg"
}
],
"headings": [
Expand All @@ -161,7 +161,7 @@
"id": 4,
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1595194682/obama_vz8qup.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1595194682/obama_vz8qup.jpg"
}
],
"headings": [
Expand Down
2 changes: 1 addition & 1 deletion src/data/innerpages/apply-to-be-a-student.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"section": "hero-image-area",
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1691979381/apply_c3hnbe.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto,g_auto/v1691979381/apply_c3hnbe.jpg"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/data/innerpages/become-a-mentor.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"section": "hero-image-area",
"images": [
{
"src": "https://res.cloudinary.com/vetswhocode/image/upload/f_auto,q_auto/v1692643962/mentor_sf2fko.jpg"
"src": "https://res.cloudinary.com/vetswhocode/image/upload/ff_auto,q_auto,g_auto/v1692643962/mentor_sf2fko.jpg"
}
]
},
Expand Down
10 changes: 10 additions & 0 deletions src/data/views.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"celebrating-progress-on-veterans-day-2023": 18,
"combat-to-code": 18,
"how-veterans-use-ai-at-vets-who-code": 19,
"introducing-the-new-and-improved-vets-who-code-app": 18,
"post-bootcamp-tips-for-rookies": 18,
"prompt-engineering-for-javascript-engineers": 19,
"why-devsecops-is-a-perfect-match-for-veterans": 18,
"why-i-created-a-portfolio-checklist-for-javaScript-engineers": 18
}
31 changes: 31 additions & 0 deletions src/lib/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ import { slugify, flatDeep } from "@utils/methods";
import { getSlugs } from "./util";
import { getAuthorByID } from "./author";

// Function to get the view count for a blog post based on its slug
const viewsFilePath = join(process.cwd(), "src/data/views.json");

function getViewCount(slug: string): number {
try {
const viewsData = JSON.parse(fs.readFileSync(viewsFilePath, 'utf8'));
return viewsData[slug] || 0; // Return the view count if exists, otherwise 0
} catch (error) {
console.error("Error reading views file:", error);
return 0; // Return 0 views in case of any error
}
}


function updateViewCount(slug: string): number {
const viewsData = JSON.parse(fs.readFileSync(viewsFilePath, 'utf8'));
if (!viewsData[slug]) {
viewsData[slug] = 0; // Initialize if not present
}
viewsData[slug] += 1; // Increment the view count
fs.writeFileSync(viewsFilePath, JSON.stringify(viewsData, null, 2)); // Write back to the file
return viewsData[slug];
}

interface BlogType extends Omit<IBlog, "category" | "tags" | "author"> {
category: string;
tags: string[];
Expand Down Expand Up @@ -36,6 +60,13 @@ export function getPostBySlug(
const { data, content } = matter(fileContents);

const blogData = data as BlogType;
// Include the view count for the article
const views = getViewCount(realSlug);


// Update and get the latest view count for the article
// Removed duplicate views definition to correct error.


let blog: IBlog;

Expand Down