Skip to content

Commit

Permalink
fix: url resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sunithvs committed Dec 30, 2024
1 parent 9b74db6 commit 36b4769
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,47 +305,46 @@

<script>
function isValidGitHubUsername(username) {
// GitHub username rules:
// 1. 1-39 characters long
// 2. Can only contain alphanumeric characters and hyphens
// 3. Cannot start or end with a hyphen
// 4. Cannot have consecutive hyphens
const githubUsernameRegex = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d]))*$/i;

return username
&& username.length >= 1
&& username.length <= 39
&& githubUsernameRegex.test(username);
}
// Function to fetch user profile data
const custom_username = 'suni';
let profile_url = ''
const pathParts = window.location.pathname.split('/').filter(part => part);
const username = pathParts[0];
if (!username || !isValidGitHubUsername(username)) {
profile_url = '';
// GitHub username rules:
// 1. 1-39 characters long
// 2. Can only contain alphanumeric characters and hyphens
// 3. Cannot start or end with a hyphen
// 4. Cannot have consecutive hyphens
const githubUsernameRegex = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d]))*$/i;

return username
&& username.length >= 1
&& username.length <= 39
&& githubUsernameRegex.test(username);
}
else {
// first check username in data/processed_users.json
const processed_users = fetch('data/processed_users.json')
.then(response => response.json())
.then(data => {
if (username in data ){
profile_url = `https://raw.githubusercontent.com/sunithvs/devb.io/refs/heads/data/data/raw_profiles/${username}_profile.json`
}
else {
profile_url = `https://user.devb.io/user/${username}`
}
})
.catch((error) => {
profile_url = `https://user.devb.io/user/${username}`
});

let profile_url = ''

async function resolveProfileUrl() {
const pathParts = window.location.pathname.split('/').filter(part => part);
// const username = pathParts[0];
const username = pathParts[0];

if (!username || !isValidGitHubUsername(username)) {
return '';
}

try {
const response = await fetch('data/processed_users.json');
const data = await response.json();

if (username in data) {
return `https://raw.githubusercontent.com/sunithvs/devb.io/refs/heads/data/data/raw_profiles/${username}_profile.json`;
}
return `https://user.devb.io/user/${username}`;
} catch (error) {
return `https://user.devb.io/user/${username}`;
}
}
console.log(profile_url)

async function fetchUserProfile() {

async function fetchUserProfile() {
profile_url = await resolveProfileUrl();
// If no username or invalid username, render 404
if (!profile_url) {
renderNotFoundPage();
Expand Down

0 comments on commit 36b4769

Please sign in to comment.