Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Static Medium feed #276

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules/
public
/themes/navhub-v2/static/css/nav.css
/themes/navhub-v2/static/css/nav.css.map
data/medium.json
3 changes: 1 addition & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ HUGO_VERSION = "0.53"

[build]
publish = "public"
command = "gulp sass && hugo"
command = "gulp sass && npm run data-medium && hugo"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Netlify will download the feed. You can do it manually with npm run data-medium. This should probably go into the readme or combined into package.json scripts.


[[redirects]]
from = "https://navcore.org/*"
Expand Down Expand Up @@ -85,4 +85,3 @@ command = "gulp sass && hugo"
to = "https://navhub.org/assets"
status = 301
force = true

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"webpack-cli": "^3.3.5"
},
"scripts": {
"data-medium": "mkdir -p data && node tools/rss-to-json.js https://medium.com/feed/nav-coin ./data/medium.json",
Copy link
Author

@tcrowe tcrowe Jan 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download into Hugo's data directory

"start": "hugo server",
"sass": "gulp sass:watch",
"build": "webpack --mode production",
Expand Down
14 changes: 5 additions & 9 deletions themes/navhub-v2/layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ <h2>Community News and Articles</h2>
<span class="fa fa-chevron-right"></span>
</a>
</div>
<div id="react-latest-news">
<div class="status-container">
<h3>Loading...</h3>
</div>
<div id="latest-news" class="card-container">
{{ range first 8 .Site.Data.medium.items }}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limit 8 from Hugo data

{{ partial "news/news_card.html" . }}
{{ end }}
</div>
</div>

{{ partial "home/projects_section.html" . }}

{{ partial "home/events_section.html" . }}
Expand All @@ -31,9 +31,5 @@ <h3>Loading...</h3>

{{ partial "footer.html" . }}

<!-- React components. -->
<script src="/js/react/vendor.bundle.js"></script>
<script src="/js/react/latest-news.js"></script>

</body>
</html>
15 changes: 15 additions & 0 deletions themes/navhub-v2/layouts/partials/news/news_card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="homepage-news-card">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just ported from the React js.

<a href="{{ .link }}}" target="_blank">
<div class="title-container"><h1>{{ .title }}</h1></div>
<div class="lower-section">
<div class="project-author">
<span class="fa fa-user-circle-o"></span>
{{ .creator }}
</div>
<div class="project-date">
<span class="fa fa-calendar"></span>
<span>{{ dateFormat "2 January 2006" .pubDate }} </span>
</div>
</div>
</a>
</div>
3 changes: 2 additions & 1 deletion themes/navhub-v2/static/css/sass/homepage/news_section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
src: url(/fonts/BIG-JOHN.otf);
}

#react-latest-news {
#latest-news {
min-height: 253px;
}

Expand Down Expand Up @@ -119,6 +119,7 @@
}
.fa {
margin-right: 5px;
color: #7d5ab5;
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions tools/rss-to-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*

Download an RSS feed, parse, and save it to a file.

Usage:
node rss-to-json url-to-rss output.json

*/


const fs = require("fs");
const path = require("path");
const Parser = require("rss-parser");
const parser = new Parser();
const [ url, outputPath ] = process.argv.slice(2);

function save(err, feed) {
if (err !== null) {
const { message, stack, status } = err;
console.log("error parsing", url, message, stack, status)
return
}

const outputSource = JSON.stringify(feed, null, " ");
fs.writeFile(outputPath, outputSource, function (err) {
if (err !== null) {
const { message, stack } = err;
console.log("error saving", outputPath, message, stack, status)
return
}
console.log("saved", outputPath)
})
}

parser.parseURL(url, save);