Skip to content

Instantly share code, notes, and snippets.

@anstosa
Created November 30, 2021 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anstosa/2727eda8ac930bdf72c0539c6565262f to your computer and use it in GitHub Desktop.
Save anstosa/2727eda8ac930bdf72c0539c6565262f to your computer and use it in GitHub Desktop.
const jobsByCategory = {
'Leadership': [],
'Engineering': [],
'Operations': [],
'Sales': [],
'Marketing': [],
'Design': [],
'Product': [],
'Recruiting': [],
};
function renderJobs() {
categories.length = 0;
wrapper.innerHTML = '';
Object.keys(jobsByCategory).forEach((category) => {
const jobs = jobsByCategory[category];
if (!jobs.length) { return; }
renderCategory(category, jobs);
});
document.querySelector('.js-careers__wrapper').classList.add('js-careers__wrapper--show');
}
function addJob(job) {
const categories = job.categories || ["Other"];
categories.forEach((category) => {
if (!jobsByCategory[category]) {
jobsByCategory[category] = [];
}
jobsByCategory[category].push(job);
})
}
const TITLES_BY_CATEGORY = {
'Leadership': ["CTO", "Cheif", "VP", "President"],
'Engineering': ["CTO", "Engineer", "Developer", "Data Scientist", "Technology"],
'Operations': ["Executive Assistant", "Finance", "Controller", "Accountant", "Accounting", "Operations", "Office Manager", "Administrative Assistant"],
'Sales': ["CRM", "Customer success", "Sales"],
'Marketing': ["Video", "Content", "Marketing", "Marketer", "Demand"],
'Design': ["Designer"],
'Recruiting': ["Recruiter", "Sourcer"],
'Product': ["Product", "Business Lead"],
'Other': []
};
function getCategories(job) {
let categories = [];
for (const currentCategory in TITLES_BY_CATEGORY) {
const titles = TITLES_BY_CATEGORY[currentCategory];
for (const index in titles) {
const currentTitle = titles[index];
if (job.title.toLowerCase().search(currentTitle.toLowerCase()) !== -1) {
categories.push(currentCategory);
break;
}
}
}
return categories;
}
function processJobs(response) {
return response.json().then((response) => {
response.jobs.forEach((job) => {
addJob({
categories: getCategories(job),
title: job.title,
url: job.absolute_url
});
});
renderJobs();
});
}
function getProcessJobs(company) {
return function processJobs(response) {
return response.json().then((response) => {
response.jobs.forEach((job) => {
let { title } = job;
let finalCompany = company;
if (company === "PSL") {
const segments = title.split(" - ");
if (segments.length === 2) {
title = segments[0];
finalCompany = segments[1]
}
}
addJob({
categories: getCategories(job),
title: `${title} - ${finalCompany}`,
url: job.absolute_url
});
});
renderJobs();
});
}
}
const wrapper = document.querySelector('.js-careers__wrapper');
const spaceClass = wrapper.firstChild.firstChild.className;
const categories = [];
wrapper.innerHTML = '';
function open(category) {
const openings = category.querySelector('.js-careers__category__openings');
openings.style.display = 'none';
category.classList.add('js-careers__category--is-selected');
}
function close(category) {
const openings = category.querySelector('.js-careers__category__openings');
category.classList.remove('js-careers__category--is-selected');
setTimeout(() => openings.style.display = 'block', 350);
}
function renderCategory(categoryName, jobs) {
const slug = categoryName.replace(/ /g, '-').toLowerCase();
const category = document.createElement('div');
category.classList.add('js-careers__job');
wrapper.appendChild(category);
categories.push(category);
category.addEventListener('click', () => {
if (category.classList.contains('js-careers__category--is-selected')) {
close(category);
} else {
open(category);
}
});
const spacer = document.createElement('div');
spacer.className = spaceClass;
category.appendChild(spacer);
const name = document.createElement('span');
name.classList.add('js-careers__category__name');
name.textContent = categoryName;
category.appendChild(name);
const content = document.createElement('div');
content.classList.add('js-careers__category__wrapper');
category.appendChild(content);
const openings = document.createElement('span');
openings.classList.add('js-careers__category__openings');
openings.textContent = `${jobs.length} Opening${jobs.length > 1 ? 's' : ''}`;
content.appendChild(openings);
const list = document.createElement('ul');
list.classList.add('js-careers__category__list');
content.appendChild(list);
sortJobs(jobs);
jobs.forEach((job) => {
const item = document.createElement('li');
item.classList.add('js-careers__category__list__item');
list.appendChild(item);
const link = document.createElement('a');
if (renderTitle(job) === "Future Founder/CEO") {
link.href = '../studio/founders';
}
else {
link.href = job.url;
}
if (!job.url.includes('psl.com')) {
link.target = '_blank';
}
link.textContent = renderTitle(job) + ' →';
link.classList.add('js-careers__category__list__item__link');
item.appendChild(link);
link.addEventListener('click', (event) => event.stopPropagation());
});
}
function renderTitle(job) {
return job.title.split(' - ').reverse().join(' - ').trim();
}
function sortJobs(jobs) {
jobs.sort((a, b) => {
const sortTitleA = a.title.includes('-') ? renderTitle(a) : `!! - ${a.title}`;
const sortTitleB = b.title.includes('-') ? renderTitle(b) : `!! - ${b.title}`;
if (sortTitleA < sortTitleB) { return -1; }
else if (sortTitleA > sortTitleB) { return 1; }
else { return 0; }
});
}
Promise.all([
fetch('https://boards-api.greenhouse.io/v1/boards/pioneersquarelabs/jobs').then(getProcessJobs('PSL')),
fetch('https://boards-api.greenhouse.io/v1/boards/remarkably/jobs').then(getProcessJobs('Remarkably')),
fetch('https://boards-api.greenhouse.io/v1/boards/adlightning/jobs').then(getProcessJobs('AdLightning')),
fetch('https://boards-api.greenhouse.io/v1/boards/glow/jobs').then(getProcessJobs('Glow')),
fetch('https://boards-api.greenhouse.io/v1/boards/yesler/jobs').then(getProcessJobs('Yesler')),
fetch('https://boards-api.greenhouse.io/v1/boards/kevala/jobs').then(getProcessJobs('Kevala')),
fetch('https://boards-api.greenhouse.io/v1/boards/gemmalabs/jobs').then(getProcessJobs('Gemmist')),
fetch('https://boards-api.greenhouse.io/v1/boards/attunely/jobs').then(getProcessJobs('Attunely')),
fetch('https://boards-api.greenhouse.io/v1/boards/shipium/jobs').then(getProcessJobs('Shipium')),
fetch('https://boards-api.greenhouse.io/v1/boards/singlefile/jobs').then(getProcessJobs('SingleFile')),
fetch('https://boards-api.greenhouse.io/v1/boards/holacash/jobs').then(getProcessJobs('Hola Cash')),
fetch('https://boards-api.greenhouse.io/v1/boards/teamsense/jobs').then(getProcessJobs('TeamSense')),
fetch('https://boards-api.greenhouse.io/v1/boards/dancechurch/jobs').then(getProcessJobs('Dance Church')),
fetch('https://boards-api.greenhouse.io/v1/boards/uplift/jobs').then(getProcessJobs('Joon')),
fetch('https://boards-api.greenhouse.io/v1/boards/secure/jobs').then(getProcessJobs('Secure')),
fetch('https://boards-api.greenhouse.io/v1/boards/genba/jobs').then(getProcessJobs('Genba')),
fetch('https://boards-api.greenhouse.io/v1/boards/recurrent/jobs').then(getProcessJobs('Recurrent')),
fetch('https://boards-api.greenhouse.io/v1/boards/boundlessimmigration/jobs').then(getProcessJobs('Boundless')),
fetch('https://boards-api.greenhouse.io/v1/boards/copperbanking/jobs').then(getProcessJobs('Copper')),
fetch('https://docs.google.com/spreadsheets/d/e/2PACX-1vS1xe0C-aM4EHpwjyllyKqsdlr0n-OF64jG2QTcJQWa2lrNdEgGrFOtbBKDfTxO27amcXKNJKd1h8O0/pub?gid=0&single=true&output=csv')
.then((response) => response.ok ? response.text() : '')
.then((csv) => {
const rows = csv.split('\n');
rows.shift(); // remove headers
rows.forEach((data) => {
const [category, name, company, url] = data.split(',');
addJob({
categories: [category],
title: `${name} - ${company}`,
url
});
});
renderJobs();
})
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment