Skip to content

Commit

Permalink
Merge pull request #112 from wcarhart/feature/bug-fixes-and-performan…
Browse files Browse the repository at this point in the history
…ce-enhancements

Small bug fixes and performance improvements
  • Loading branch information
wcarhart authored May 12, 2021
2 parents fc70557 + a10794f commit 84d7444
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 40 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cdn": "https://storage.googleapis.com/willcarh-art/"
"cdn": "https://cdn.willcarh.art/"
}
19 changes: 12 additions & 7 deletions generator/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Support dynamic asset tags:
{{sys:header}} --> generated header for HTML files
{{sys:headerjs}} --> generated header for JS files
{{sys:charizard}} --> Charizard ascii art
{{sys:preload}} --> list of all images to preload
*/

/*
Expand Down Expand Up @@ -597,8 +598,12 @@ const buildProjSpec = async (projects, page) => {
let technologiesMetadataHtml = technologiesMetadataSnippet.replace('{{technologies}}', project.languages.concat(project.technologies).filter(p => p !== '').join(' · '))
// TODO: implement github stars
let githubStarsMetadataHtml = githubStarsMetadataSnippet.replace('{{github-stars}}', '-')
// TODO: if install is empty, should not use color nor monospace font
let installMetadataHtml = installMetadataSnippet.replace('{{install}}', project.install === '' ? '-' : project.install)
let installMetadataHtml = ''
if (project.install === '') {
installMetadataHtml = installMetadataSnippet.replace('{{install}}', '-')
} else {
installMetadataHtml = installMetadataSnippet.replace('{{install}}', `<code class="inline-code">${project.install}</code>`)
}
let latestReleaseMetadataHtml = latestReleaseMetadataSnippet.replace('{{version}}', project.latest_version === '' ? '-' : project.latest_version)
let dateText = '-'
if (project.published !== '') {
Expand Down Expand Up @@ -726,6 +731,7 @@ const buildProjSuper = async (projects) => {
return html
}

// attempt to remove unsafe characters from HTML IDs, classnames, and sometimes routing
const htmlSafify = async (string) => {
return string.toLowerCase().replace(/\./g, '----').replace(/#/g, '').replace(/ /g, '_').replace(/,/g, '').replace(/'/g, '')
}
Expand Down Expand Up @@ -825,7 +831,7 @@ const buildProjAll = async (projects) => {
rowHtml = rowHtml.replace('{{project-container-featured}}', featuredContainer)

// build additional tile containers to fit in row
// TODO: this is not DRY - repeated for featured, tile, and regular - should be function
// this could probably be more DRY....but I am lazy
for (let i = 0; i < 4; i++) {
let tileProject = null
if (featuredProjects.length !== 0) {
Expand Down Expand Up @@ -988,8 +994,7 @@ const buildVaultRows = async (experiences, projects, blogs) => {
r.githubName = ''
r.linkUrl = experience.url
r.blogPost = experience.blogPost
// TODO: this should redirect to the actual exp-tab, not just the page scroll location
r.vaultLink = '{{src:about}}#experience'
r.vaultLink = `{{src:about}}?exp=${experience.companyId}#experience`

rows.push(r)
}
Expand All @@ -1012,7 +1017,7 @@ const buildVaultRows = async (experiences, projects, blogs) => {
r.githubName = project.repo
r.linkUrl = project.link
r.blogPost = project.blogPost
r.vaultLink = `{{src:project/${await htmlSafify(project.name)}}}`
r.vaultLink = `{{src:project/${project.id}}}`

rows.push(r)
}
Expand All @@ -1030,7 +1035,7 @@ const buildVaultRows = async (experiences, projects, blogs) => {
r.docsName = ''
r.githubName = ''
r.linkUrl = ''
r.blogPost = `{{src:blog/${await htmlSafify(blog.title.toLowerCase().replace(/ /g, '-'))}}}`
r.blogPost = `{{src:blog/${blog.id}}}`
r.vaultLink = r.blogPost

rows.push(r)
Expand Down
26 changes: 23 additions & 3 deletions generator/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const config = require('../config.json')
const package = require('../package.json')

const builder = require('./builder.js')
const parser = require('./parser.js')

const readdirPromise = util.promisify(fs.readdir)
const readFilePromise = util.promisify(fs.readFile)
Expand All @@ -21,8 +22,6 @@ const mkdirPromise = util.promisify(fs.mkdir)
const truncatePromise = util.promisify(fs.truncate)
const copyFilePromise = util.promisify(fs.copyFile)

// TODO: add verbose comments

// generate HTML files based on page type
const generate = async (page, develop) => {
// set up file structure
Expand Down Expand Up @@ -135,7 +134,7 @@ const buildScripts = async (develop) => {
}
}

// build style elements
// build style elements: css/*, ico/*, font/*
const buildStyles = async () => {
try {
await fs.promises.access('src/css')
Expand Down Expand Up @@ -239,6 +238,7 @@ const buildDynamicAsset = async (data, match, asset, level, develop) => {
let resolvedData = data
const now = Date().toLocaleString()
let headerData = null, headerjsData = null, charizard = null, message = null
let projects = null, blogs = null, img = null, icofiles = null
switch (asset) {
case 'develop':
resolvedData = resolvedData.replace(match, develop)
Expand Down Expand Up @@ -272,6 +272,26 @@ const buildDynamicAsset = async (data, match, asset, level, develop) => {
message += '\n-->\n'
resolvedData = resolvedData.replace(match, message)
break
case 'preload':
projects = await parser.parse('project')
blogs = await parser.parse('blog')
img = []
for (let p of projects) {
if (p.visibility !== 'none') {
img.push(p.img)
}
}
for (let b of blogs) {
img.push(b.cover)
}
icofiles = await readdirPromise('ico')
for (let ico of icofiles) {
if (ico.endsWith('.png')) {
img.push(`{{ico:${ico}}}`)
}
}
resolvedData = resolvedData.replace(match, await resolveAssets(`[${img.map(i => `'${i}'`).join(',')}]`, 1, develop))
break
default:
throw new Error(`Unknown system asset: '${asset}'`)
}
Expand Down
5 changes: 3 additions & 2 deletions generator/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const generateFileTree = async () => {
console.log(tree)
}

// recursive function for pretty printing file trees
const buildTree = async (dir, indent, isTail, result) => {
let stats = await statPromise(dir)
let files = []
Expand Down Expand Up @@ -91,6 +92,7 @@ const parseArgs = async (args) => {
return parsedArgs
}

// run generator
const main = async () => {
try {
const args = await parseArgs(process.argv.slice(2))
Expand All @@ -104,9 +106,8 @@ const main = async () => {
// clear out source directory
await rmdirPromise('src/', { recursive: true })

// TODO: this shouldn't matter
// asset order is essential, due to how linking occurs:
// - scripts must be built first
// - scripts must be built first and styles must be first
// - vault must be built before projects
const assets = ['scripts', 'style', 'home', 'vault', 'demo', 'about', 'blog', 'projects', 'etc']
for (let asset of assets) {
Expand Down
1 change: 1 addition & 0 deletions generator/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const entities = require('./entities.js')

const readFilePromise = util.promisify(fs.readFile)

// define validation strategies for each entity
const SUPPORTED_ENTITIES = {
experience: {
content: 'content/experience.md',
Expand Down
63 changes: 38 additions & 25 deletions js/expselector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,46 @@

// init tabs
$(document).ready(async () => {
// if URL contains query parameter 'exp', we want to switch to that experience tab
let urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('exp')) {
selectExperience({'override': urlParams.get('exp')})
}

// dynamically update div height after selecting experience
$('#exp-content-container').css('height', $('.exp-active').height())
})

// handle new click on experience
$(document).ready(async () => {
$('.exp-selector').click(function() {

// get our selected experience
const exp = this.id.split('-').pop()

// toggle selectors
const selectors = $('.exp-selector')
for (let s of selectors) {
$(s).removeClass('exp-selector-active')
}
$(this).addClass('exp-selector-active')

// toggle content
const content = $('.exp-content')
for (let c of content) {
$(c).removeClass('exp-active')
$(c).addClass('exp-hidden')
}
$(`#exp-details-${exp}`).removeClass('exp-hidden')
$(`#exp-details-${exp}`).addClass('exp-active')

// set height of content container
$('#exp-content-container').css('height', $(`#exp-details-${exp}`).height())
})
})
$('.exp-selector').click(selectExperience)
})

function selectExperience({override=''}) {
// get our selected experience
let exp = ''
if (override === '') {
exp = this.id.split('-').pop()
} else {
exp = override
}

// toggle selectors
const selectors = $('.exp-selector')
for (let s of selectors) {
$(s).removeClass('exp-selector-active')
}
$(`#exp-selector-${exp}`).addClass('exp-selector-active')

// toggle content
const content = $('.exp-content')
for (let c of content) {
$(c).removeClass('exp-active')
$(c).addClass('exp-hidden')
}
$(`#exp-details-${exp}`).removeClass('exp-hidden')
$(`#exp-details-${exp}`).addClass('exp-active')

// set height of content container
$('#exp-content-container').css('height', $(`#exp-details-${exp}`).height())
}
10 changes: 10 additions & 0 deletions js/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{sys:headerjs}}

// images to preload
const photos = {{sys:preload}}

// preload images from CDN
for (const photo of photos) {
let img = new Image()
img.src = photo
}
2 changes: 1 addition & 1 deletion js/profilephoto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// rotate profile pictures on about page
$(document).ready(async () => {

// TODO: add more pictures?
// registered photos
const photos = [
'{{cdn:img/profile.jpg}}',
'{{cdn:img/profile4.jpeg}}',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<p class="project-metadata-label">INSTALL</p>
<p class="project-metadata-value"><code class="inline-code">{{install}}</code></p>
<p class="project-metadata-value">{{install}}</p>
1 change: 1 addition & 0 deletions templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<script src="{{js:anchorjump.js}}"></script>
<script src="{{js:expselector.js}}"></script>
<script src="{{js:aboutpagetidbit.js}}"></script>
<script async src="{{js:preload.js}}"></script>
</head>
<body>

Expand Down
Empty file removed templates/app_index.html
Empty file.
Empty file removed templates/app_specific.html
Empty file.
1 change: 1 addition & 0 deletions templates/blog_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<!-- willcarh.art scripts -->
<script src="{{js:darkmode.js}}"></script>
<script src="{{js:year.js}}"></script>
<script async src="{{js:preload.js}}"></script>
<!-- blogcards script is loaded after body for performance reasons -->
</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions templates/demo_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<script src="{{js:darkmode.js}}"></script>
<script src="{{js:year.js}}"></script>
<script src="{{js:demorows.js}}"></script>
<script async src="{{js:preload.js}}"></script>
</head>
<body>

Expand Down
1 change: 1 addition & 0 deletions templates/etc.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<script src="{{js:year.js}}"></script>
<script src="{{js:anchorjump.js}}"></script>
<script src="{{js:etc.js}}"></script>
<script async src="{{js:preload.js}}"></script>
</head>
<body>
<!-- text content -->
Expand Down
1 change: 1 addition & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<script src="{{js:email.js}}"></script>
<script src="{{js:homepagetidbit.js}}"></script>
<script src="{{js:data.js}}"></script>
<script async src="{{js:preload.js}}"></script>
</head>
<body>

Expand Down
1 change: 1 addition & 0 deletions templates/project_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<script src="{{js:darkmode.js}}"></script>
<script src="{{js:year.js}}"></script>
<script src="{{js:linkicons.js}}"></script>
<script async src="{{js:preload.js}}"></script>
<!-- projectcards script is loaded after body for performance reasons -->
</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions templates/vault.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<script src="{{js:year.js}}"></script>
<script src="{{js:linkicons.js}}"></script>
<script src="{{js:vaultrows.js}}"></script>
<script async src="{{js:preload.js}}"></script>
</head>
<body>

Expand Down

0 comments on commit 84d7444

Please sign in to comment.