diff --git a/app.py b/app.py index 241f144..8aad0d0 100644 --- a/app.py +++ b/app.py @@ -12,11 +12,48 @@ class WikiApp(Flask): super().__init__(*args, **kwargs) # Define routes - self.route('/', methods=['GET'])(self.homepage) + # self.route('/', methods=['GET'])(self.homepage) + self.route('/', methods=['GET'])(self.homepage_new) + self.route('/publications', methods=['GET'])(self.fetch_publications) + self.route('/meetups', methods=['GET'])(self.fetch_meetups) self.route('/', methods=['GET'])(self.page_content) self.route('/favicon.ico')(self.favicon) self.route('/archive/', methods=['GET'])(self.get_collection) + def homepage_new(self): + pages = ['Homepage'] + homepage_content = '' + for page in pages: + # Make a request to MediaWiki API to get content of a specific page + response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'parse', 'page': page, 'format': 'json'}) + data = response.json() + # Extract page title and content + page_content = data['parse']['text']['*'] + page_content = self.fix_html(page_content) + homepage_content += page_content + + return render_template('cn-home.html', nav_elements=self.get_nav_menu(), content=homepage_content) + + def fetch_publications(self): + concepts = ['Newsletters', 'Projects'] + publication_page_list = self.fetch_all_pages(concepts) + updated_cat_list = self.fetch_pages_cat(publication_page_list) + projects = updated_cat_list.get('Projects', []) + newsletters = updated_cat_list.get('Newsletters', []) + nav_elements = self.get_nav_menu() + + return render_template('publications.html', projects=projects, newsletters=newsletters, nav_elements=nav_elements) + + def fetch_meetups(self): + concepts = ['Meetups'] + # publication_page_list = self.fetch_all_pages(concepts) + # updated_cat_list = self.fetch_pages_cat(publication_page_list) + # meetups = updated_cat_list.get('Meetups', []) + nav_elements = self.get_nav_menu() + meetup_content = self.fetch_page('Meetups') + + return render_template('meetups.html', content=meetup_content, nav_elements=nav_elements) + def fetch_pages_cat(self, category_page_list): all_pages_string = '|'.join(page for pages in category_page_list.values() for page in pages) thumb_resp = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={ @@ -41,15 +78,12 @@ class WikiApp(Flask): category_page_list[category][page_title].update({'pageid':pageid, 'title': title, 'source': source }) return category_page_list - - - + def fetch_all_pages(self, categories): category_page_list = {} for category in categories: response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'ask', 'query': '[[Concept:'+category+']]|?Article:Date', 'format': 'json', 'formatversion': '2'}) data = response.json() - print(data) page_title_timestamps = {} for page_title, page_data in data['query']['results'].items(): if 'printouts' in page_data and 'Article:Date' in page_data['printouts']: @@ -61,8 +95,7 @@ class WikiApp(Flask): category_page_list[category] = page_title_timestamps return category_page_list - - + def homepage(self): # Fetch pages for articles, projects, and newsletters categories = ['Articles', 'Projects', 'Newsletters'] @@ -85,13 +118,25 @@ class WikiApp(Flask): page_content = self.fix_html(page_content) return render_template('article.html', nav_elements=self.get_nav_menu(), title=page_title, content=page_content) + def fetch_page(self, title): + # Make a request to MediaWiki API to get content of a specific page + response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'parse', 'page': title, 'format': 'json'}) + data = response.json() + # Extract page title and content + page_title = data['parse']['title'] + page_content = data['parse']['text']['*'] + page_content = self.fix_html(page_content) + return page_content + def get_nav_menu(self): response = requests.get(self.MEDIAWIKI_BASE_URL + self.BASE_API, params={'action': 'ask', 'query': '[[Concept:MainNavigation]]', 'format': 'json', 'formatversion': '2'}) data = response.json() main_navigation_elements = {} for page_title, page_data in data['query']['results'].items(): main_navigation_elements[page_title] = {'title':page_data.get('fulltext', '')} - return main_navigation_elements + reversed_main_navigation = list(main_navigation_elements.items())[::-1] + reversed_main_navigation = dict(reversed_main_navigation) + return reversed_main_navigation def fix_html(self, page_content): soup = BeautifulSoup(page_content, 'html.parser') @@ -110,7 +155,7 @@ class WikiApp(Flask): for link in links: # Add _blank to href link['target'] = '_blank' - link.string = link.string.strip() + " ↘" + link.string = link.string.strip() + " ↗" # Find all a tags with href containing 'index.php' links = soup.find_all('a', href=lambda href: href and 'index.php' in href) diff --git a/static/assets/styles.css b/static/assets/styles.css index 9dd2ffa..30a764f 100644 --- a/static/assets/styles.css +++ b/static/assets/styles.css @@ -3,8 +3,8 @@ /* styles.css */ body { font-family: Arial, sans-serif; - background-color: black; - color: white; + background-color: white; + color: black; margin: auto; padding: 0px; font-family: "Space Mono", monospace; @@ -21,7 +21,7 @@ body { .header-title { font-size: 40px; display: flex; - background-color: black; + background-color: white; width: fit-content; padding: 10px; padding-left: 20px; @@ -31,7 +31,7 @@ body { .header-title a { text-decoration: none; - color: white; + color: black; } .header-summary { @@ -54,28 +54,28 @@ body { .nav-element-cont { display: flex; flex-direction: row; - gap: 10px; + gap: 20px; text-transform: lowercase; font-size: 25px; width: 100%; - background-color: white; + background-color: black; padding:20px; align-items: center; } .nav-element-cont a{ text-decoration: none; - color: black; + color: white; } .nav-element { display: flex; flex-direction: row; - gap: 10px; + gap: 20px; } .line { - background-color: white; + background-color: black; width: 100%; height: 1px; padding: 0; @@ -133,9 +133,9 @@ body { } .content-cont .article-cont a { - color: black; + color: white; text-decoration: none; - background-color: white; + background-color: black; font-style: oblique; padding-left: 5px; padding-right: 5px; @@ -155,7 +155,7 @@ body { height: 100%; width: auto; max-width: 900px; - border: white; + border: black; border-style: dashed; transition: transform 0.3s ease-in-out; } @@ -178,7 +178,7 @@ body { height: 100vh; display: flex; flex-direction: row; - justify-content: space-between; + justify-content: space-around; } .collection-cont { @@ -196,7 +196,7 @@ body { border: 2px; border-radius: 20px; border-style: solid; - border-color: white; + border-color: black; padding: 10px; } @@ -214,7 +214,7 @@ body { .content-cont .collection-cont a { text-decoration: underline; - color: white; + color: black; } .collection-cont .section-img{ @@ -229,7 +229,7 @@ body { max-width: 200px; object-fit: contain; border-radius: 0px; - border: white; + border: black; border-style: dashed; transition: transform 0.3s ease-in-out; } @@ -264,7 +264,7 @@ body { .section-element a { text-decoration: underline; - color: white; + color: black; } .section-img img{ @@ -272,7 +272,7 @@ body { height: 200px; object-fit: cover; border-radius: 0px; - border: white; + border: black; border-style: dashed; transition: transform 0.3s ease-in-out; } diff --git a/templates/base.html b/templates/base.html index 5284fc1..7947749 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,10 +13,8 @@ diff --git a/templates/cn-home.html b/templates/cn-home.html new file mode 100644 index 0000000..1c8f8b4 --- /dev/null +++ b/templates/cn-home.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block title %}Ø | CONCEPTNULL {% endblock %} +{% block content %} +
+

+
+ {{ content | safe }} +
+
+
+{% endblock %} diff --git a/templates/meetups.html b/templates/meetups.html new file mode 100644 index 0000000..6ee8248 --- /dev/null +++ b/templates/meetups.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block title %} Ø | Meetups {% endblock %} +{% block content %} + +
+

Meetups

+
+ {{ content | safe }} +
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/publications.html b/templates/publications.html new file mode 100644 index 0000000..1d755b3 --- /dev/null +++ b/templates/publications.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} +{% block title %} Ø | Publications{% endblock %} +{% block content %} +
+
+
NEWSLETTERS
+
+ {% for key, values in newsletters.items() %} + + +
+ {% endfor %} +
+
+
+
PROJECTS
+
+ {% for key, values in projects.items() %} + + +
+ {% endfor %} +
+
+
+ +{% endblock %} \ No newline at end of file