Skip to content

Commit

Permalink
feature to add dynamic content creation (pythonindia#170)
Browse files Browse the repository at this point in the history
* remove pages, add flexibility to generate content for any folder.
  • Loading branch information
bhansa authored Aug 31, 2023
1 parent 8d72163 commit acf81e4
Show file tree
Hide file tree
Showing 23 changed files with 499 additions and 349 deletions.
5 changes: 1 addition & 4 deletions data/coc.md → _pages-content/code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: default
slug: code-of-conduct
title: Code Of Conduct
header: Code Of Conduct
bloglike: true
nav: code-of-conduct
---

### The Short Form
Expand Down
6 changes: 5 additions & 1 deletion data/faq.md → _pages-content/faq.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
slug: faq
title: Frequently Asked Questions
---

### What is PyCon India?

Expand Down Expand Up @@ -74,4 +78,4 @@ No. Each track is planned at its full capacity.
### Contact Us
- For general queries: [[email protected]](mailto:[email protected])
- For ticket queries: [[email protected]](mailto:[email protected])
- Zulip Chat: [https://pyconindia.zulipchat.com/](https://pyconindia.zulipchat.com/)
- Zulip Chat: [https://pyconindia.zulipchat.com/](https://pyconindia.zulipchat.com/)
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
layout: default
slug: reporting-guide
title: Reporting Guide
header: Reporting Guide
bloglike: true
nav: reporting-guide
---

At PyCon India 2023, we are committed to providing a safe and welcoming
Expand Down
5 changes: 5 additions & 0 deletions data/tinkeringSpace.md → _pages-content/tinkering-space.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
slug: tinkering-space
title: Tinkering Space
---

### Join the Tinkering Space!

Are you ready to embark on an extraordinary full-day adventure with your little ones? PyCon India is thrilled to introduce the Tinkering Space, a unique experimental track designed to foster new learning experiences at the conference. We cordially invite parents to bring their children and dive into the world of creativity and innovation through hands-on tinkering with cutting-edge hardware.
Expand Down
4 changes: 4 additions & 0 deletions data/travel.md → _pages-content/travel.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
slug: travel
title: Getting to PyCon India 2023
---
# Travel Information for PyCon India 2023 in Hyderabad

Welcome to PyCon India 2023 in Hyderabad! Below you'll find detailed travel information on how to reach the conference venue.
Expand Down
4 changes: 4 additions & 0 deletions data/ylw.md → _pages-content/ylw.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
slug: ylw
title: Young Learners Workshop
---
### What is the Young Learners Workshop (YLW)?

YLW promotes code literacy among school students with Python programming language using engaging hardware (ex: Raspberry Pi devices). This is an opportunity for students, teachers to learn from each other and from the Indian Python community to cultivate their programming, communication and technology skills.
Expand Down
17 changes: 0 additions & 17 deletions components/coc.js

This file was deleted.

17 changes: 0 additions & 17 deletions components/faqs.js

This file was deleted.

17 changes: 0 additions & 17 deletions components/reporting_guide.js

This file was deleted.

17 changes: 0 additions & 17 deletions components/tinkeringSpace.js

This file was deleted.

17 changes: 0 additions & 17 deletions components/travel.js

This file was deleted.

17 changes: 0 additions & 17 deletions components/ylw.js

This file was deleted.

41 changes: 41 additions & 0 deletions lib/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from "fs";
import { join } from "path";
import matter from "gray-matter";

export function getPostSlugs(directory) {
const postsDirectory = join(process.cwd(), directory);
return fs.readdirSync(postsDirectory);
}

export function getPostBySlug(postsDirectory, slug, fields = []) {
const realSlug = slug.replace(/\.md$/, "");
const fullPath = join(postsDirectory, `${realSlug}.md`);
const fileContents = fs.readFileSync(fullPath, "utf8");
const { data, content } = matter(fileContents);

const items = {};

// Ensure only the minimal needed data is exposed
fields.forEach((field) => {
if (field === "slug") {
items[field] = realSlug;
}
if (field === "content") {
items[field] = content;
}

if (typeof data[field] !== "undefined") {
items[field] = data[field];
}
});

return items;
}

export function getAllPosts(postsDirectory, fields) {
const slugs = getPostSlugs(postsDirectory);
const posts = slugs.map((slug) =>
getPostBySlug(postsDirectory, slug, fields)
);
return posts;
}
Loading

0 comments on commit acf81e4

Please sign in to comment.