Skip to content

Commit d52130c

Browse files
committed
added course editor and 10 added new post
1 parent cd637d8 commit d52130c

File tree

18 files changed

+702
-1116
lines changed

18 files changed

+702
-1116
lines changed

.firebase/hosting.cHVibGlj.cache

Lines changed: 375 additions & 938 deletions
Large diffs are not rendered by default.

gatsby-node.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@ exports.createPages = async function ({ actions, graphql }) {
1717
}
1818
}
1919
}
20-
allCourseCategoryCsv {
21-
nodes {
22-
name
23-
slug
24-
}
25-
}
2620
allCourseCsv {
21+
distinct(field: category)
2722
nodes {
2823
id
29-
slug
3024
title
3125
featureimage
3226
category
@@ -57,7 +51,7 @@ exports.createPages = async function ({ actions, graphql }) {
5751
data.allPostCatgoriesCsv.nodes.forEach((nodes) => {
5852
const name = nodes.name;
5953
actions.createPage({
60-
path: name.split(" ").join("-").toLowerCase(),
54+
path: name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, ''),
6155
component: require.resolve("./src/templates/catPosts.js"),
6256
context: { name },
6357
});
@@ -68,24 +62,23 @@ exports.createPages = async function ({ actions, graphql }) {
6862
const Postid = nodes.id;
6963
const CategoryName = nodes.category
7064
actions.createPage({
71-
path: name.split(" ").join("-").toLowerCase(),
65+
path: name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, ''),
7266
component: require.resolve("./src/templates/coursePost.js"),
7367
context: { Postid, CategoryName },
7468
});
7569
});
7670

77-
data.allCourseCategoryCsv.nodes.forEach((nodes) => {
78-
const name = nodes.name;
79-
actions.createPage({
80-
path: name.split(" ").join("-").toLowerCase(),
71+
data.allCourseCsv.distinct.forEach((name) => {
72+
actions.createPage({
73+
path: name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, ''),
8174
component: require.resolve("./src/templates/courseCatPost.js"),
8275
context: { name },
8376
});
8477
});
8578

8679
data.allMdx.nodes.forEach((post) => {
8780
actions.createPage({
88-
path: post.frontmatter.title.split(" ").join("-").toLowerCase(),
81+
path: post.frontmatter.title.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, ''),
8982
component: require.resolve("./src/templates/mdxsinglePost.js"),
9083
context: {
9184
title: post.frontmatter.title,

posts/__pycache__/main.cpython-37.pyc

7.27 KB
Binary file not shown.

posts/__pycache__/main.cpython-39.pyc

448 Bytes
Binary file not shown.

posts/courses/Course.csv

Lines changed: 17 additions & 0 deletions
Large diffs are not rendered by default.

posts/main.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@
77
from datetime import datetime
88
from typing import Optional, List
99
import shutil
10+
import pandas as pd
11+
import requests
12+
from scrapy import Selector
13+
import re
14+
15+
16+
17+
def getdata(url, coupon=""):
18+
if url[:21] in "https://www.udemy.com":
19+
data = requests.get(url).content
20+
sel = Selector(text = data)
21+
description = sel.css("div.ud-component--course-landing-page-udlite--description").extract()
22+
TAG_RE = re.compile(r'<button .+>.+button>')
23+
title = sel.css("h1 ::text").extract()[0]
24+
descriptionclean = TAG_RE.sub('', description[0]).replace('style="max-height:221px"',"")
25+
category = sel.css("a.udlite-heading-sm:nth-of-type(2) ::text").extract()[0]
26+
imagefile = sel.xpath("//meta[@property='og:image']/@content").extract()[0]
27+
date = datetime.now().strftime("%Y-%m-%d")
28+
data = {
29+
"title": title.replace("\n",""),
30+
"category": category,
31+
"date": date,
32+
"course_url":url,
33+
"coupon":coupon,
34+
"featureimage": imagefile,
35+
"description": descriptionclean,
36+
}
37+
return data
38+
return "None"
39+
40+
1041

1142

1243
app = FastAPI()
@@ -166,3 +197,39 @@ async def UpdatedPost(request: Request, title: str = Form(...), content: str = F
166197

167198

168199

200+
@app.get("/listofcourse")
201+
def listofcourse(request: Request):
202+
data = pd.read_csv("./courses/Course.csv")
203+
return templates.TemplateResponse("listofcourse.html", {"request": request,"alltitle": data["title"]})
204+
205+
@app.post("/listofcourse")
206+
def delete(request: Request, title : str = Form(...)):
207+
path = "./courses/Course.csv"
208+
data = pd.read_csv(path)
209+
index = data[data['title'] == title].index
210+
data.drop(index, inplace=True)
211+
data.to_csv(path, header = True, index = False)
212+
return templates.TemplateResponse("listofcourse.html", {"request": request,"alltitle": data["title"]})
213+
214+
215+
@app.post("/createcourese")
216+
async def createcourse(request:Request, url: str = Form(...)):
217+
path = "./courses/Course.csv"
218+
df = pd.read_csv(path)
219+
data = getdata(url)
220+
df2 = pd.DataFrame([[data["title"], data['category'], data['date'], data['coupon'], data['course_url'], data['featureimage'], data['description']] ], columns = df.columns)
221+
df2.to_csv(path, mode = 'a', header = False, index = False)
222+
df = pd.read_csv(path)
223+
224+
225+
return templates.TemplateResponse("listofcourse.html", {"request": request,"alltitle": df["title"]})
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+

posts/templates/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<br />
3535
<br />
3636
<a type="button" href="/copytomarkdown" class="btn btn-danger">Paste to markdown</a>
37+
<br />
38+
<br />
39+
<a type="button" href="/listofcourse" class="btn btn-danger">course</a>
3740
</center>
3841

3942
</div>

posts/templates/listofcourse.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Document</title>
7+
<link
8+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
9+
rel="stylesheet"
10+
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"
11+
crossorigin="anonymous"
12+
/>
13+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
14+
15+
</head>
16+
<body>
17+
<div class="container">
18+
{% if success %}
19+
<br />
20+
<div class="alert alert-danger" role="alert">
21+
<p>Successful Deleted Post</p>
22+
</div>
23+
{% endif %}
24+
{% if successPost %}
25+
<br />
26+
<div class="alert alert-success" role="alert">
27+
<p>Successful Updated Post</p>
28+
</div>
29+
{% endif %}
30+
<br />
31+
<a type="button" href="/" class="btn btn-primary">Back to Home</a>
32+
33+
<h1> List of Post </h1>
34+
<form method="post" class="row g-3">
35+
{% for i,j in alltitle.items() %}
36+
<br />
37+
38+
<div class="form-check">
39+
<input
40+
class="form-check-input"
41+
type="radio"
42+
name="title"
43+
value="{{j}}"
44+
required
45+
46+
/>
47+
<label class="form-check-label" > {{j}} </label>
48+
</div>
49+
{% endfor %}
50+
51+
<button type="submit" class="btn btn-danger" formaction="/listofcourse" required>Delere Course post</button>
52+
</form>
53+
54+
<form method="post" class="row g-3">
55+
<label class="form-label">URL Course free</label>
56+
<input type="text" class="form-control" name="url">
57+
<button type="submit" class="btn btn-primary" formaction="/createcourese" required>Create Course post</button>
58+
</form>
59+
</div>
60+
</body>
61+
</html>

src/components/Card/AllCard.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ const HomeFeatureCard = (props) => {
1616
<NewCardContent
1717
image={post.frontmatter.featureImage.childImageSharp.fluid}
1818
catlink={post.frontmatter.category
19-
.split(" ")
20-
.join("-")
21-
.toLowerCase()}
19+
.toLowerCase().replace(/ /g, '-')
20+
.replace(/[^\w-]+/g, '')}
2221
cat={post.frontmatter.category}
2322
title={post.frontmatter.title}
2423
link={`/${post.frontmatter.title
25-
.split(" ")
26-
.join("-")
27-
.toLowerCase()}`}
24+
.toLowerCase().replace(/ /g, '-')
25+
.replace(/[^\w-]+/g, '')}`}
2826
time={post.timeToRead}
2927
/>
3028
</Col>
@@ -44,15 +42,13 @@ const AllPostCard = (props) => {
4442
<NewCardContent
4543
image={post.frontmatter.featureImage.childImageSharp.fluid}
4644
catlink={post.frontmatter.category
47-
.split(" ")
48-
.join("-")
49-
.toLowerCase()}
45+
.toLowerCase().replace(/ /g, '-')
46+
.replace(/[^\w-]+/g, '')}
5047
cat={post.frontmatter.category}
5148
title={post.frontmatter.title}
5249
link={`/${post.frontmatter.title
53-
.split(" ")
54-
.join("-")
55-
.toLowerCase()}`}
50+
.toLowerCase().replace(/ /g, '-')
51+
.replace(/[^\w-]+/g, '')}`}
5652
time={post.timeToRead}
5753
/>
5854
</Col>
@@ -72,10 +68,10 @@ const AllCourseCard = (props) => {
7268
<Col style={{marginBottom: "20px"}} {...props}>
7369
<NewCardContent
7470
image={post.localImage.childImageSharp.fluid}
75-
catlink={post.category.split(" ").join("-").toLowerCase()}
71+
catlink={post.category.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}
7672
cat={post.category}
7773
title={post.title}
78-
link={`/${post.slug}`}
74+
link={`/${post.title.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}`}
7975
/>
8076
</Col>
8177
))}
@@ -94,10 +90,10 @@ const AllHomeCourseCard = (props) => {
9490
<Col style={{marginBottom: "20px"}} {...props}>
9591
<NewCardContent
9692
image={post.localImage.childImageSharp.fluid}
97-
catlink={post.category.split(" ").join("-").toLowerCase()}
93+
catlink={post.category.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}
9894
cat={post.category}
9995
title={post.title}
100-
link={`/${post.title.split(" ").join("-").toLowerCase()}`}
96+
link={`/${post.title.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}`}
10197
/>
10298
</Col>
10399
))}
@@ -119,16 +115,10 @@ const HomeAllPostCard = (props) => {
119115
<Col style={{marginBottom: "20px"}} {...props} >
120116
<NewCardContent
121117
image={post.frontmatter.featureImage.childImageSharp.fluid}
122-
catlink={post.frontmatter.category
123-
.split(" ")
124-
.join("-")
125-
.toLowerCase()}
118+
catlink={post.frontmatter.category.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}
126119
cat={post.frontmatter.category}
127120
title={post.frontmatter.title}
128-
link={`/${post.frontmatter.title
129-
.split(" ")
130-
.join("-")
131-
.toLowerCase()}`}
121+
link={`/${post.frontmatter.title.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}`}
132122
time={post.timeToRead}
133123
/>
134124
</Col>
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React from "react";
2-
import { Header , ItemCat} from "../styles/RecentPosts";
3-
import {Card} from "../styles/CardStyle";
4-
2+
import { Header, ItemCat } from "../styles/RecentPosts";
3+
import { Card } from "../styles/CardStyle";
54

65
export const CategoryPost = ({ data }) => {
76
return (
8-
<div style={{marginBottom: "20px"}} >
9-
<Header>Category</Header>
10-
<Card style={{paddingBottom: "120px"}} >
11-
12-
{data.map((node) => (
13-
<ItemCat to={`/${node.slug}`}>{node.name}</ItemCat>
7+
<div style={{ marginBottom: "20px" }}>
8+
<Header>Category</Header>
9+
<Card style={{ paddingBottom: "120px" }}>
10+
{data.map((name) => (
11+
<ItemCat to={`/${name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')}`}>
12+
{name}
13+
</ItemCat>
1414
))}
15-
</Card>
16-
</div>
15+
</Card>
16+
</div>
1717
);
1818
};

0 commit comments

Comments
 (0)