Skip to content

Commit

Permalink
feat: create picture gallery yearly (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal authored Jan 7, 2022
1 parent 9b23eeb commit e847a49
Show file tree
Hide file tree
Showing 8 changed files with 1,176 additions and 1,078 deletions.
63 changes: 63 additions & 0 deletions __tests__/__snapshots__/md-formatter.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,69 @@ and my paragraph is cool
"
`;

exports[`process events images 1`] = `
"# Table of Contents
- [Year of 2016](#2016) - total events 1
- [Year of 2017](#2017) - total events 1
- [Year of 2021](#2021) - total events 2
# 2016
![Total Events](https://img.shields.io/badge/total-1-blue?style=flat-square)
<table>
<tr>
<td align=\\"center\\"> <img src=\\"https://pbs.twimg.com/media/CbgOxYzWAAAjvgp?format=jpg&name=4096x4096\\" width=\\"85\\" height=\\"50\\" /> </td>
<td align=\\"center\\"> <img src=\\"https://pbs.twimg.com/media/CbgOy-pXEAE4PVp?format=jpg&name=4096x4096\\" width=\\"85\\" height=\\"50\\" /> </td>
</tr>
</table>
| Date | Event | Title | Slides | Recording | Location | Language |
| ---- | ----- | ----- | ------ | --------- | -------- | -------- |
| 2016-1-1 | name | title | [Slides](https://example.com) | [Recording](https://example.com) | US | |
# 2017
![Total Events](https://img.shields.io/badge/total-1-blue?style=flat-square)
| Date | Event | Title | Slides | Recording | Location | Language |
| ---- | ----- | ----- | ------ | --------- | -------- | -------- |
| 2017-1-1 | name | title | [Slides](https://example.com) | [Recording](https://example.com) | US | |
# 2021
![Total Events](https://img.shields.io/badge/total-2-blue?style=flat-square) ![Total Meetups](https://img.shields.io/badge/meetups-1-violet?style=flat-square) ![Total Conferences](https://img.shields.io/badge/conferences-1-red?style=flat-square)
<table>
<tr>
<td align=\\"center\\"> <img src=\\"https://pbs.twimg.com/media/CbgOxYzWAAAjvgp?format=jpg&name=4096x4096\\" width=\\"85\\" height=\\"50\\" /> </td>
<td align=\\"center\\"> <img src=\\"https://pbs.twimg.com/media/CbgOy-pXEAE4PVp?format=jpg&name=4096x4096\\" width=\\"85\\" height=\\"50\\" /> </td>
</tr>
</table>
| Date | Event | Title | Slides | Recording | Location | Language |
| ---- | ----- | ----- | ------ | --------- | -------- | -------- |
| 2021-2-1 | name | title | [Slides](https://example.com) | | | English |
| 2021-2-2 | name | title | | [Recording](https://example.com) | US | English |
"
`;

exports[`process events json data to provide a complete markdown document 1`] = `
"# Table of Contents
Expand Down
3 changes: 0 additions & 3 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ test('given a directory of markdown files a full document is rendered', async ()

test('given a directory of markdown files a full document is rendered along with pre and post content', async () => {
const filePath = path.join(__dirname, './__fixtures__/main-datafiles')
console.log('---------------------------->')
console.log(filePath)
console.log('---------------------------->')
const jsonResult = await generateDocument({
sourceDirectory: filePath,
preContent: [
Expand Down
114 changes: 112 additions & 2 deletions __tests__/md-formatter.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getConfig } from '../bin/config-manager.js'
import { formatToMarkdown, getEventsMd } from '../src/utils/md-formatter.js'

test('convert json object to markdown formatting', async () => {
Expand All @@ -13,7 +14,7 @@ test('convert json object to markdown formatting', async () => {
expect(markdown).toMatchSnapshot()
})

test('process events json data to provide a complete markdown document', () => {
test('process events json data to provide a complete markdown document', async () => {
const events = [
{
year: 2016,
Expand Down Expand Up @@ -147,6 +148,115 @@ test('process events json data to provide a complete markdown document', () => {
}
]

const markdown = getEventsMd(events)
const markdown = await getEventsMd(events)
expect(markdown).toMatchSnapshot()
})

test('process events images', async () => {
const myConfig = {
output: {
includePictureGalleryYearly: true
}
}

// @TODO what we actually need to do is refactor config-manager.js
// to really have a getConfig that reads from a processed config
// so it doesn't re-evaluate all the time, but then also have a
// setConfig that allows to override the config
await getConfig(myConfig)

const events = [
{
year: 2016,
items: [
{
attributes: {
date: new Date('2016-01-01'),
title: 'title',
type: 'conference',
name: 'name',
slides_url: 'https://example.com',
recording_url: 'https://example.com',
country_code: 'US',
language: null,
images: [
'https://pbs.twimg.com/media/CbgOxYzWAAAjvgp?format=jpg&name=4096x4096',
'https://pbs.twimg.com/media/CbgOy-pXEAE4PVp?format=jpg&name=4096x4096'
]
}
}
],
stats: {
total: 1
}
},
{
year: 2017,
items: [
{
attributes: {
date: new Date('2017-01-01'),
title: 'title',
name: 'name',
type: 'conference',
slides_url: 'https://example.com',
recording_url: 'https://example.com',
country_code: 'US',
language: null
}
}
],
stats: {
total: 1
}
},
{
year: 2021,
items: [
{
attributes: {
date: new Date('2021-02-01'),
title: 'title',
type: 'conference',
name: 'name',
slides_url: 'https://example.com',
recording_url: null,
country_code: null,
language: 'English',
images: [
'https://pbs.twimg.com/media/CbgOxYzWAAAjvgp?format=jpg&name=4096x4096'
]
}
},
{
attributes: {
date: new Date('2021-02-02'),
title: 'title',
type: 'meetup',
name: 'name',
slides_url: null,
recording_url: 'https://example.com',
country_code: 'US',
language: 'English',
images: [
'https://pbs.twimg.com/media/CbgOy-pXEAE4PVp?format=jpg&name=4096x4096'
]
}
}
],
stats: {
total: 2,
total_podcast: 0,
total_conference: 1,
total_webinar: 0,
total_meetup: 1,
total_article: 0,
total_workshop: 0,
total_other: 0
}
}
]

const markdown = await getEventsMd(events)
expect(markdown).toMatchSnapshot()
})
27 changes: 16 additions & 11 deletions bin/config-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ const configFileName = 'gigsboat.json'
const __dirname = process.cwd()
let gigsConfig = undefined

export async function getConfig() {
export async function getConfig(providedConfig) {
if (gigsConfig) {
return gigsConfig
}

try {
const jsonConfigFileContents = await fs.readFile(
path.join(__dirname, configFileName),
'utf8'
)
gigsConfig = JSON.parse(jsonConfigFileContents)
} catch (error) {
// debug
// console.error(error)
if (providedConfig) {
gigsConfig = providedConfig
} else {
try {
const jsonConfigFileContents = await fs.readFile(
path.join(__dirname, configFileName),
'utf8'
)
gigsConfig = JSON.parse(jsonConfigFileContents)
} catch (error) {
// debug
// console.error(error)
}
}

validateConfig(gigsConfig)
Expand All @@ -40,7 +44,8 @@ function validateConfig(config) {
output: {
type: 'object',
properties: {
markdownFile: { type: 'string', default: 'README-gigsfile.md' }
markdownFile: { type: 'string', default: 'README-gigsfile.md' },
includePictureGalleryYearly: { type: 'boolean', default: true }
},
default: {}
},
Expand Down
Loading

0 comments on commit e847a49

Please sign in to comment.