Skip to content

Commit

Permalink
Merge pull request #661 from oddbird/build-mail-archive
Browse files Browse the repository at this point in the history
Fetch Mail archives on build
  • Loading branch information
jamesnw committed Jul 11, 2024
2 parents 1266a60 + 99b38a8 commit 957e74f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions content/_data/newsletterArchive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import eleventyFetch from '@11ty/eleventy-fetch';

export default async () => {
const url =
'https://oddbird.us19.list-manage.com/generate-js/?u=80219aa68d7bad77b9fd2eb93&fid=27537&show=10';
const res = await eleventyFetch(url, {
type: 'text',
duration: '0s',
directory: '.cache/eleventy-fetch/',
dryRun: false,
});
const archives = res.replace(/^document.write\(/, '').replace(/\);$/, '');

try {
return JSON.parse(archives);
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed fetching OddNews archive.', e);
return '';
}
};
8 changes: 4 additions & 4 deletions content/oddnews.njk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ summary: |
) }}
</aside>

{{ layout.title('Latest News') }}
{% if newsletterArchive | length %}
{{ layout.title('Latest News') }}

<div class="oddnews-archive">
<script language="javascript" src="//oddbird.us19.list-manage.com/generate-js/?u=80219aa68d7bad77b9fd2eb93&fid=27537&show=10" type="text/javascript"></script>
</div>
{{ newsletterArchive | safe }}
{% endif %}

0 comments on commit 957e74f

Please sign in to comment.