Skip to content

Commit

Permalink
fix: add regex to get links from markdown and render them correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan-Palan committed Feb 18, 2025
1 parent d77e36c commit f528df8
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 47 deletions.
108 changes: 61 additions & 47 deletions _layouts/gsoc.html
Original file line number Diff line number Diff line change
@@ -1,58 +1,72 @@
---
layout: default
---
<div class="cover" style="z-index: 20">
<h3 class="cohort_title">{{ page.title }}</h3>

<div class="program">
{% include partials/gsoc-community.html %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>{{ page.title }}</title>
<script src="/js/linkify.js" defer></script>
</head>

<div class="project-details">
<div class="card-content">
{{ page.video_embed }}
</div>

<h5 class="black-text heading">Project Ideas</h5>
{% if page.projects %}
<ul class="project-item">
{% for project in page.projects %}
<li>
<strong>{{ project.name }}</strong><br>
{{ project.description | markdownify }}
</li>
{% endfor %}
</ul>
{% endif %}
<body>
<div class="cover" style="z-index: 20">
<h3 class="cohort_title">{{ page.title }}</h3>

{% if page.recommended_skills %}
<h3 class="project-list">Recommended Skills:</h3>
<p class="program-p">{{ page.recommended_skills }}</p>
{% endif %}
<div class="program">
<div class="community-details">
{% include partials/gsoc-community.html %}
</div>

{% if page.mentors %}
<h3 class="project-list">Mentors:</h3>
<ul>
{% for mentor in page.mentors %}
<li>{{ mentor }}</li>
{% endfor %}
</ul>
{% endif %}
<div class="project-details">
<div class="card-content">
<div class="image-div">{{ page.video_embed }}</div>
</div>

{% if page.issues %}
<h3 class="project-list">Issue(s):</h3>
{% for issue_link in page.issues %}
<a class="issue" href="{{ issue_link }}">{{ issue_link }}</a><br />
{% endfor %}
{% endif %}
{% if page.projects %}
<h5 class="black-text heading">Project Ideas</h5>
{% for project in page.projects %}
<ul class="project-item">
<ol>
<b class="replace-links">{{ project.name }}</b>
</ol>
<ol class="replace-links">
{{ project.description }}
</ol>
</ul>
{% endfor %} {% endif %} {% if page.recommended_skills %}
<h3 class="project-list">Recommended Skills:</h3>
<p class="program-p replace-links">{{ page.recommended_skills }}</p>
{% endif %} {% if page.mentors %}
<h3 class="project-list">Mentors:</h3>
<ul>
{% for mentor in page.mentors %}
<li style="padding-bottom: 1rem" class="replace-links">
- {{ mentor }}
</li>
{% endfor %}
</ul>
{% endif %} {% if page.issues %}
<h3 class="project-list">Issue:</h3>
{% for issue_link in page.issues %}
<a class="issue" href="{{ issue_link }}">{{ issue_link }}</a><br />
{% endfor %} {% endif %}

<br />
<a href="https://slack.meshery.io">
<input type="button" value="Participate" class="participate-btn appear" />
</a>
<br />
<a href="https://slack.meshery.io">
<input
type="button"
value="Participate"
class="participate-btn appear"
/>
</a>
</div>
</div>
</div>
</div>
</div>

<div class="text subscribe program__subscribe">
{% include subscribe.html %}
</div>
<div class="text subscribe program__subscribe">
{% include subscribe.html %}
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions js/linkify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
document.addEventListener("DOMContentLoaded", function () {
// Regex pattern to match [text](link)
const linkPattern = /\[([^\]]+)\]\(([^\)]+)\)/g;

// Find all elements that might contain the [label](url) pattern
const elementsToReplace = document.querySelectorAll(".replace-links");

elementsToReplace.forEach((el) => {
const originalText = el.textContent;
const newHTML = originalText.replace(linkPattern, (match, label, url) => {
return `<a href="${url}">${label}</a>`;
});
el.innerHTML = newHTML;
});
});

0 comments on commit f528df8

Please sign in to comment.