Skip to content

Commit

Permalink
feat: add common file for each course
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesx00 committed Dec 21, 2024
1 parent 41c2947 commit 4d3713c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 184 deletions.
30 changes: 9 additions & 21 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const markdownItAnchor = require("markdown-it-anchor");
const hljs = require("highlight.js");

const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginBundle = require("@11ty/eleventy-plugin-bundle");
const pluginNavigation = require("@11ty/eleventy-navigation");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
Expand All @@ -19,8 +18,6 @@ const customCollections = require("./eleventy.config.collection.js");

/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
module.exports = function (eleventyConfig) {
// eleventyConfig.addPlugin(pluginSyntaxHighlight);
// const highlighter = eleventyConfig.markdownHighlighter;
eleventyConfig.ignores.add("./src/courses/*/*/files/**/*");
eleventyConfig.addMarkdownHighlighter((str, language) => {
if (language === "mermaid") {
Expand All @@ -30,18 +27,7 @@ module.exports = function (eleventyConfig) {
language = "plaintext";
}
return hljs.highlight(str, { language }).value;
// return highlighter(str, language);
});
// eleventyConfig.addPlugin(pluginMermaid);
// eleventyConfig.addPlugin(eleventyPluginSyntaxHighlighter);
// const highlighter = eleventyConfig.markdownHighlighter;
// eleventyConfig.addMarkdownHighlighter((str, language) => {
// console.log(language);
// if (language === "mermaid") {
// return `<pre class="mermaid">${str}</pre>`;
// }
// // return highlighter(str, language);
// });
// To Support .yaml Extension in _data
// You may remove this if you can use JSON
eleventyConfig.addDataExtension("yaml", (contents) => yaml.load(contents));
Expand All @@ -68,20 +54,15 @@ module.exports = function (eleventyConfig) {
// https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets

// Watch content images for the image pipeline.
eleventyConfig.addWatchTarget("src/**/*.{svg,webp,png,jpeg}");
eleventyConfig.addWatchTarget("src/**/*.{svg,webp,png,jpeg,py}");

// App plugins
eleventyConfig.addPlugin(pluginDrafts);
eleventyConfig.addPlugin(pluginImages);
eleventyConfig.addPlugin(customCollections);
// eleventyConfig.addPlugin(pluginMermaid);
// eleventyConfig.addPlugin(syntaxHighlight);

// Official plugins
eleventyConfig.addPlugin(pluginRss);
// eleventyConfig.addPlugin(pluginSyntaxHighlight, {
// preAttributes: { tabindex: 0 },
// });
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(pluginBundle);
Expand Down Expand Up @@ -152,7 +133,14 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addShortcode("fileContent", (inputPath, fileName) => {
const directory = path.dirname(inputPath);
const fullPath = path.join(directory, "files", fileName);
return fs.readFileSync(fullPath);
try {
return fs.readFileSync(fullPath);
} catch (e) {
// read from one directory up to common course files
const directory = path.dirname(path.dirname(inputPath));
const fullPath = path.join(directory, "files", fileName);
return fs.readFileSync(fullPath);
}
});

// Features to make your build faster (when you need them)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ file_groups:
is_hidden: true
is_main: true
is_test_file: false
source: main.py
source: setup_data.py
id: 1
name: Python
---
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ file_groups:
is_hidden: true
is_main: true
is_test_file: false
source: main.py
source: setup_data.py
- file_name: tests.py
file_type: python
id: 476
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ file_groups:
is_hidden: true
is_main: true
is_test_file: false
source: main.py
source: setup_data.py
- file_name: tests.py
file_type: python
id: 479
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ file_groups:
is_hidden: true
is_main: true
is_test_file: false
source: main.py
source: setup_data.py
- file_name: tests.py
file_type: python
id: 486
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import sqlite3
import os
from faker import Faker
from prettytable import from_db_cursor, MARKDOWN
from enum import Enum

def setup(connection):
fake = Faker()
Faker.seed(0)

cur = connection.cursor()

cur.execute("CREATE TABLE customers(first_name, last_name, age, gender)")

class Gender(Enum):
M = "M"
F = "F"

for i in range(10):
cur.execute(
"INSERT INTO customers (first_name, last_name, age, gender) VALUES (?, ?, ?, ?)",
(
fake.first_name(),
fake.last_name(),
fake.pyint(max_value=80) + 20,
fake.enum(Gender).value)
)

if __name__ == "__main__":

con = sqlite3.connect("tutorial.db")
cur = con.cursor()
setup(connection=con)
query = open('query.sql', 'r').read()
try:
res = cur.execute(query)
table = from_db_cursor(cur)
print(table)
except Exception as e:
import sqlite3
import os
from faker import Faker
from prettytable import from_db_cursor, MARKDOWN
from enum import Enum

def setup(connection):
fake = Faker()
Faker.seed(0)

cur = connection.cursor()

cur.execute("CREATE TABLE customers(first_name, last_name, age, gender)")

class Gender(Enum):
M = "M"
F = "F"

for i in range(10):
cur.execute(
"INSERT INTO customers (first_name, last_name, age, gender) VALUES (?, ?, ?, ?)",
(
fake.first_name(),
fake.last_name(),
fake.pyint(max_value=80) + 20,
fake.enum(Gender).value)
)

if __name__ == "__main__":

con = sqlite3.connect("tutorial.db")
cur = con.cursor()
setup(connection=con)
query = open('query.sql', 'r').read()
try:
res = cur.execute(query)
table = from_db_cursor(cur)
print(table)
except Exception as e:
print("Error:", str(e))

0 comments on commit 4d3713c

Please sign in to comment.