Skip to content

Commit

Permalink
Merge pull request #1295 from tilburgsciencehub/finish-and-check-site…
Browse files Browse the repository at this point in the history
…maps

Check and complete sitemap
  • Loading branch information
krzysztof99xd authored Oct 10, 2024
2 parents 50759f0 + acfa30c commit 3da0f92
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def inject_git_commit_hash():
def inject_data():
with app.app_context():
# Execute function to load data
data_dict = build_data_dict(Topics, articles)
data_dict = build_data_dict(Contributors, blogs, Topics, articles)
popular_pages = load_popular_pages(app)

return dict(data_dict=data_dict, popular_pages=popular_pages)
Expand Down Expand Up @@ -336,7 +336,7 @@ def sitemap():

# Sitemap without redirects
with app.app_context():
data_dict = build_data_dict(Topics, articles)
data_dict = build_data_dict(Contributors, blogs, Topics, articles)
sitemap = generate_sitemap(app, data_dict, base_url=base_url)

# Redirects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ author: "Aakriti Gupta"
authorlink: ""
aliases:
- /iv
-

---

---


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
draft: false
title: "Introduction"
weight: 1
type: subcategory

---
Binary file not shown.
Binary file not shown.
49 changes: 42 additions & 7 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ def urlize(text):

# Build a data dictionary from topics and articles
# Parameters:
# - contributors: SQLAlchemy query object for contributors
# - blogs: SQLAlchemy query object for blogs
# - topics: SQLAlchemy query object for topics
# - articles: SQLAlchemy query object for articles
# Returns:
# - Dictionary containing structured data of topics and articles
def build_data_dict(topics, articles):
def build_data_dict(contributors, blogs, topics, articles):
data_dict = {}
contributors_data = contributors.query.all()
blogs_data = blogs.query.all()
topics_data = topics.query.all()
topic_dict = defaultdict(lambda: defaultdict(list))

Expand All @@ -65,7 +69,21 @@ def serialize_article(article):
'date': article.date,
'draft': article.draft
}

def serialize_blog(blog):
return{
'id': blog.id,
'title': blog.title,
'description': blog.description,
'path': blog.path
}
def serialize_contributor(contributor):
return{
'id': contributor.id,
'name': contributor.name,
'path': contributor.path,
'description_short': contributor.description_short
}

def serialize_topic(topic, level, parent, articles):
return {
'id': topic.id,
Expand All @@ -88,9 +106,13 @@ def build_structure(level, parent, articles):

articles_examples = articles.query.filter_by(type='examples').all()
serialized_articles_examples = [serialize_article(article) for article in articles_examples]
serialized_blogs = [serialize_blog(blog) for blog in blogs_data]
serialized_contributors = [serialize_contributor(contributor) for contributor in contributors_data]

data_dict['topics'] = build_structure(1, 1, articles)
data_dict['examples'] = serialized_articles_examples
data_dict['contributors'] = serialized_contributors
data_dict['blogs'] = serialized_blogs

return data_dict

Expand Down Expand Up @@ -318,7 +340,7 @@ def add_url_element(urlset, loc, date=None, priority="0.8", changefreq="monthly"
url = ET.SubElement(urlset, "url")

loc_element = ET.SubElement(url, "loc")
loc_element.text = loc
loc_element.text = loc.lower()

priority_element = ET.SubElement(url, "priority")
priority_element.text = priority
Expand All @@ -337,23 +359,36 @@ def process_topics(topics, parent_path=""):
for topic in topics:
if topic['draft'] != 'true':
full_path = f"{parent_path}/{topic['path']}".strip("/")
add_url_element(urlset, f"{base_url}/topics/{full_path}")
add_url_element(urlset, f"{base_url}/topics/{full_path}/")
process_topics(topic.get('childtopics', []), full_path)
for article in topic.get('articles', []):
if article['draft'] != 'true':
article_path = f"{full_path}/{article['path']}".strip("/")
add_url_element(urlset, f"{base_url}/topics/{article_path}", date = article['date'])
article_path = f"{full_path}/{article['path']}"
article_path = article_path.lower()
add_url_element(urlset, f"{base_url}/topics/{article_path}/", date = article['date'])

# Process topics and articles
process_topics(data['topics'])

# Process examples
for example in data.get('examples', []):
if example['draft'] != 'true':
example_path = f"{base_url}/examples/{example['path']}".strip("/")
example_path = f"{base_url}/examples/{example['path']}/"
example_path = example_path.lower()
add_url_element(urlset, example_path, date=example.get('date'))

# Process blogs
for blog in data.get('blogs', []):
blog_path = f"{base_url}/blog/{blog['path']}/"
blog_path = blog_path.lower()
add_url_element(urlset, blog_path)

# Process contributors
for contributor in data.get('contributors', []):
contributor_name_path = contributor['path'].replace('-', '')
contributor_path = f"{base_url}/contributors/{contributor_name_path}/"
contributor_path = contributor_path.lower()
add_url_element(urlset, contributor_path)

# Non dynamic routes
rules = list(app.url_map.iter_rules())
Expand Down
58 changes: 57 additions & 1 deletion redirectstsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def redirect_271():

@app.route('/tutorials/more-tutorials/contribute-to-tilburg-science-hub/add-contributor/')
def redirect_272():
return redirect(url_for('home', _external=True) + "topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/add-contributor/", code=301)
return redirect(url_for('home', _external=True) + "topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/add-contributor/", code=301)

@app.route('/tutorials/reproducible-research-and-automation/principles-of-project-setup-and-workflow-management/structure_phd_2013')
def redirect_273():
Expand Down Expand Up @@ -1721,3 +1721,59 @@ def redirect_428():
@app.route('/building-blocks/analyze-data/regression-discontinuity/rd-plots/')
def redirect_429():
return redirect(url_for('home', _external=True) + "topics/analyze/causal-inference/rdd/rd-plots/", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/tutorial-shell/')
def redirect_430():
return redirect(url_for('home', _external=True) + "topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/tutorial-shell/", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/pullrequests/')
def redirect_431():
return redirect(url_for('home', _external=True) + "/topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/pullrequests/", code=301)

@app.route('/building-blocks/analyze-data/regressions/survival-analysis-lubridate/')
def redirect_432():
return redirect(url_for('home', _external=True) + "topics/analyze/regression/linear-regression/survival-analysis-lubridate/", code=301)

@app.route('/building-blocks/')
def redirect_433():
return redirect(url_for('home', _external=True) + "topics/", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/')
def redirect_434():
return redirect(url_for('home', _external=True) + "topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/style-guide')
def redirect_435():
return redirect(url_for('home', _external=True) + "/topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/style-guide", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/building-block-shell/')
def redirect_436():
return redirect(url_for('home', _external=True) + "/topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/building-block-shell", code=301)

@app.route('/contributors/matthijs_vangils')
def redirect_437():
return redirect(url_for('home', _external=True) + "/contributors/matthijsvangils", code=301)

@app.route('/topics/collect-store/data-collection/databases/')
def redirect_438():
return redirect(url_for('home', _external=True) + "/topics/collect-store/data-storage/databases", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/add-contributor')
def redirect_439():
return redirect(url_for('home', _external=True) + "/topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/add-contributor", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/homepage-cards')
def redirect_440():
return redirect(url_for('home', _external=True) + "/topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/homepage-cards", code=301)

@app.route('/disclaimer')
def redirect_441():
return redirect(url_for('home', _external=True) + "/blog/disclaimer", code=301)

@app.route('/topics/collaborate-share/project-management/engage-open-science/contribute-to-tilburg-science-hub/code-of-conduct/')
def redirect_442():
return redirect(url_for('home', _external=True) + "/topics/collaborate-share/project-management/contribute-to-tilburg-science-hub/code-of-conduct", code=301)

@app.route('/contributors/kleintob')
def redirect_443():
return redirect(url_for('home', _external=True)+ "/contibutors/tobiasklein", code=301)
2 changes: 1 addition & 1 deletion sitemap.xml

Large diffs are not rendered by default.

0 comments on commit 3da0f92

Please sign in to comment.