Skip to content

Commit

Permalink
fixed github cors issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphGL committed Jun 11, 2023
1 parent 8ac8dad commit 4c2d737
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

body {
all: unset;
background: rgb(20, 21, 25);
background: var(--bg-color);
background: radial-gradient(circle, rgba(20, 21, 25, 1) 0%, rgba(16, 17, 20, 1) 100%);
background-attachment: fixed;
color: var(--fg-color);
Expand Down
1 change: 1 addition & 0 deletions src/lib/Pagination.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
--current;
}
}
function nextPage() {
if (current < numOfPages - 1) {
++current;
Expand Down
42 changes: 12 additions & 30 deletions src/lib/Projects/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,20 @@ type Project = {

export async function getProjects(noOfItems?: number, page?: number): Promise<Project[]> {
const github = await fetch(
'https://github.com/RaphGL?tab=repositories&q=&type=source&language=&sort=stargazers'
`https://api.github.com/users/raphgl/repos?type=sources&sort=pushed&per_page=${noOfItems}&page=${page}`
);
const pageText = await github.text();
const parser = new DOMParser();
const pageDOM = parser.parseFromString(pageText, 'text/html');
const projectsJSON = await github.json();

const projectsElems = pageDOM.querySelectorAll('div.col-10.col-lg-9.d-inline-block');
let projects: Project[] = [];

for (const elem of projectsElems) {
let projectName = elem.querySelector('h3.wb-break-all a');
let projectDescription = elem.querySelector('p.col-9.d-inline-block.color-fg-muted.mb-2.pr-4');
let projectTagElems = elem.querySelectorAll('a.topic-tag.topic-tag-link.f6.my-1');

let projectTags = [];
for (let tag of projectTagElems) {
projectTags.push(tag.innerHTML);
}

projects.push({
name: projectName?.innerHTML as string,
href: ('https://github.com' + projectName?.getAttribute('href')) as string,
description: projectDescription?.innerHTML as string,
tags: projectTags
});
let projects = [];
for (const project of projectsJSON) {
if (!project.fork)
projects.push({
name: project.name,
href: project.html_url,
description: project.description,
tags: project.topics
});
}

if (noOfItems) {
return projects.slice(0, noOfItems);
} else if (noOfItems && page) {
return projects.slice(page * noOfItems, noOfItems);
} else {
return projects;
}
return projects;
}
1 change: 0 additions & 1 deletion src/routes/projects/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
onMount(() => {
getProjects().then((projs) => {
projects = projs;
console.log(projects);
});
});
</script>
Expand Down

0 comments on commit 4c2d737

Please sign in to comment.