Skip to content

Commit bbf3eae

Browse files
committed
Improved Twitter links
1 parent 432eecb commit bbf3eae

File tree

5 files changed

+81
-28
lines changed

5 files changed

+81
-28
lines changed

.eleventy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const filter = require('./_includes/filter');
66
const scAvatar = require('./_includes/shortcodes/avatar');
77
const scResponsiveImage = require('./_includes/shortcodes/responsive-image');
88
const scSocialSvg = require('./_includes/shortcodes/social-svg');
9-
const scMeetupDetails = require('./_includes/shortcodes/meetup-details');
109
const scVideoPlayer = require('./_includes/shortcodes/video-player');
10+
const pscMeetupDetails = require('./_includes/shortcodes/meetup-details');
1111

1212
/**
1313
* Add date properties to collections.
@@ -62,12 +62,6 @@ module.exports = (eleventyConfig) => {
6262
// FILTER: Replace text with regex capabilities.
6363
eleventyConfig.addFilter('regexReplace', filter.regexReplace);
6464

65-
// SHORTCODE: Format meeting details message block.
66-
eleventyConfig.addShortcode('meetupDetails', scMeetupDetails);
67-
68-
// SHORTCODE: Embed video players for event replay.
69-
eleventyConfig.addShortcode('videoPlayer', scVideoPlayer);
70-
7165
// SHORTCODE: Resize and cache images.
7266
eleventyConfig.addLiquidShortcode('avatar', scAvatar);
7367

@@ -77,6 +71,12 @@ module.exports = (eleventyConfig) => {
7771
// SHORTCODE: Add social icon SVG block.
7872
eleventyConfig.addLiquidShortcode('socialSvg', scSocialSvg);
7973

74+
// SHORTCODE: Embed video players for event replay.
75+
eleventyConfig.addShortcode('videoPlayer', scVideoPlayer);
76+
77+
// SHORTCODE: Format meeting details message block.
78+
eleventyConfig.addPairedShortcode('meetupDetails', pscMeetupDetails);
79+
8080
// PLUGIN: RSS feed
8181
eleventyConfig.addPlugin(pluginRss);
8282

_includes/shortcodes/meetup-details.js

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,57 @@ const fullDate = (dateValue) => {
1818
return `${monthNames[newDate.getMonth()]} ${newDate.getDate()}, ${newDate.getFullYear()}`;
1919
};
2020

21+
/**
22+
* Create Twitter search link with page URL
23+
*
24+
* @param {string} content Text for link
25+
* @param {string} pageUrl Page URL
26+
*
27+
* @return {string} Fully formed Twitter search link
28+
*/
29+
const tweetSearch = (content, pageUrl) => {
30+
// const url = `${siteData.url.replace('https://', '')}/posts/meetups/`;
31+
// ^^ use if less specific searches are desired ^^
32+
const url = `${siteData.url.replace('https://', '')}${pageUrl}`;
33+
const search = encodeURIComponent(url);
34+
35+
return `<a href="https://twitter.com/search?q=${search}">${content}</a>`;
36+
};
37+
38+
/**
39+
* Create Twitter tweet link with page title and URL
40+
*
41+
* @param {string} content Text for link
42+
* @param {string} pageUrl Page URL
43+
* @param {string} pageTitle Page Title
44+
*
45+
* @return {string} Fully formed Twitter share link
46+
*/
47+
const tweetPost = (content, pageUrl, pageTitle) => {
48+
const settings = {
49+
text: `Meetup: "${pageTitle}"`,
50+
url: `${siteData.url.replace('https://', '')}${pageUrl}`,
51+
via: siteData.author.twitter,
52+
};
53+
const params = Object.entries(settings)
54+
.reduce((acc, item) => `${acc}${item[0]}=${encodeURIComponent(item[1])}&`, '');
55+
56+
return `<a href="https://twitter.com/intent/tweet?${params.slice(0, -1)}">${content}</a>`;
57+
};
58+
2159
/**
2260
* Provide template for meeting details.
2361
*
62+
* @param {string} meetHeader The meeting header (optional)
2463
* @param {string} meetDate The meet date
2564
* @param {string} venue The venue
2665
* @param {string} after The after party gathering place
27-
* @param {string} msgHeader The message header (optional)
2866
* @param {string} meetTitle The meet title (optional)
29-
* @param {string} meetUrl The meet url (optional)
67+
* @param {string} msgHeader The message header (optional)
3068
*
3169
* @return {string} Completed template
3270
*/
33-
module.exports = function meetupDetails(meetDate, venue, after, msgHeader, meetTitle, meetUrl) {
71+
module.exports = function meetupDetails(meetHeader, meetDate, venue, after, meetTitle, msgHeader) {
3472
const header = msgHeader || 'Meetup details';
3573

3674
const svgBlock = `<svg display="none">
@@ -39,12 +77,6 @@ module.exports = function meetupDetails(meetDate, venue, after, msgHeader, meetT
3977
<g id="location-sharp"><path d='M256,32C167.67,32,96,96.51,96,176c0,128,160,304,160,304S416,304,416,176C416,96.51,344.33,32,256,32Zm0,224a64,64,0,1,1,64-64A64.07,64.07,0,0,1,256,256Z'/></g>
4078
</svg>`;
4179

42-
const meetHeaderBlock = meetTitle && meetUrl
43-
? `<div class="title is-size-4">
44-
<a href="${meetUrl}">${meetTitle}</a>
45-
</div>`
46-
: '';
47-
4880
const venueOrg = venue
4981
? organizations[venue]
5082
: {};
@@ -74,7 +106,7 @@ module.exports = function meetupDetails(meetDate, venue, after, msgHeader, meetT
74106
</div>
75107
76108
<div class="message-body">
77-
${meetHeaderBlock}
109+
${meetHeader}
78110
79111
<div>
80112
DATE
@@ -102,11 +134,15 @@ module.exports = function meetupDetails(meetDate, venue, after, msgHeader, meetT
102134
${venueLocation}
103135
</div>
104136
137+
<small>
138+
(Check back here or on ${tweetSearch('Twitter', this.page.url)} for updates.)
139+
</small>
140+
105141
${afterBlock}
106142
107-
<p class="has-margin-top">
108-
Check back here or <a href="https://twitter.com/${siteData.author.twitter}">@${siteData.author.twitter} on Twitter</a> for updates.
109-
</p>
143+
<div class="has-margin-top">
144+
Help ${tweetPost('spread the word on Twitter', this.page.url, meetTitle)}.
145+
</div>
110146
</div>
111147
</div>`;
112148
};

_includes/shortcodes/responsive-image.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
const Image = require('@11ty/eleventy-img');
22

3-
module.exports = async (src, alt, outputFormat = 'jpeg') => {
3+
module.exports = async (src, alt, outputFormats = 'jpeg') => {
44
if (alt === undefined) {
55
throw new Error(`Responsive Image: missing ALT attribute from: ${src}`);
66
}
77

8+
const sizes = '(max-width: 400px) 400px, (max-width: 800px) 800px, 100vw';
9+
const formats = outputFormats.split(',');
10+
811
try {
912
const stats = await Image(src, {
10-
formats: [outputFormat],
13+
formats,
1114
urlPath: '/assets/img/',
1215
outputDir: '_site/assets/img/',
1316
widths: [400, 800, null],
1417
});
1518

16-
const lowestSrc = stats[outputFormat][0];
17-
const sizes = '(max-width: 400px) 400px, (max-width: 800px) 800px, 100vw';
18-
const sourceBlock = Object.values(stats).map((imageFormat) => `<source type="image/${imageFormat[0].format}" srcset="${imageFormat.map((entry) => `${entry.url} ${entry.width}w`).join(', ')}" sizes="${sizes}">`).join('\n');
19+
const defaultSrc = stats[formats.slice(-1)][0];
20+
const sourceBlock = Object.values(stats).map((imageFormat) => `<source
21+
type="image/${imageFormat[0].format}"
22+
srcset="${imageFormat.map((entry) => `${entry.url} ${entry.width}w`).join(', ')}"
23+
sizes="${sizes}">`)
24+
.join('\n');
25+
const imgBlock = `<img
26+
src="${defaultSrc.url}"
27+
width="${defaultSrc.width}"
28+
height="${defaultSrc.height}"
29+
alt="${alt}"
30+
loading="lazy">`;
1931

2032
return `<picture class="image">
2133
${sourceBlock}
22-
<img src="${lowestSrc.url}" width="${lowestSrc.width}" height="${lowestSrc.height}" alt="${alt}" loading="lazy">
34+
${imgBlock}
2335
</picture>`;
2436
} catch (err) {
2537
// eslint-disable-next-line no-console

_layouts/meetup.liquid

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ layout: base
88
{{ content | safe }}
99
</div>
1010

11-
{%- meetupDetails page.date, venue, after -%}
11+
{%- meetupDetails page.date, venue, after, title -%}
12+
{%- endmeetupDetails -%}
1213

1314
{%- videoPlayer video, title -%}
1415
</div>

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ <h1 class="is-sr-only">{{ title }}</h1>
1111

1212
<section class="meetup-details">
1313
{%- assign meet = collections.meetups | last -%}
14-
{%- meetupDetails meet.date, meet.data.venue, meet.data.after, 'Upcoming meetup details', meet.data.title, meet.url -%}
14+
{%- meetupDetails meet.date, meet.data.venue, meet.data.after, meet.data.title, 'Upcoming meetup details' -%}
15+
<div class="title is-size-4">
16+
<a href="{{ meet.url }}">{{ meet.data.title }}</a>
17+
</div>
18+
{%- endmeetupDetails -%}
1519

1620
<meta id="meet-date" time="{{ meet.date }}">
1721
<script>

0 commit comments

Comments
 (0)