Skip to content

Commit e599323

Browse files
committed
chore: add rone site to examples
1 parent b3f7788 commit e599323

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+9775
-20
lines changed

.env.example

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
AIRTABLE_API_KEY=your_api_key_here
2-
BASE_ID=base_id_here
3-
# table id also works. must be between quotation marks (" ") if the name is more than one word
4-
TABLE_ID="Table ID here"
5-
# name or id of view (optional). must be between quotation marks (" ") if the name is more than one word
6-
VIEW="Grid view here"
7-
# Determines the order in which fields will be displayed on the page for an individual row.
8-
# If a field isn't contained in this variable, it will not be displayed at all.
9-
FIELD_ORDER="Field1,Field2,Etc,Here"
10-
# Determines the order in which fields will be displayed for each row on the homepage.
11-
# If a field isn't contained in this variable, it will not be displayed at all.
12-
HOMEPAGE_FIELD_ORDER="Field1,Field2,Etc,Here"
13-
# title for header that will appear at the top of each page
14-
HEADER_TITLE="Header Title"
15-
# title for the website, which will be displayed in the browser tab
16-
PAGE_TITLE_FIELD="Name"
17-
# any fields listed here will be rendered in markdown if possible
18-
SITE_TITLE="Site Title"
19-
# if present, values from this column of your table will be used to populate the page title in the form `Page Title – Site Title`
20-
MARKDOWN_FIELDS="Field1,Field2,Etc,Here"
1+
AIRTABLE_API_KEY="keyacWNmaPG1VwR7Z"
2+
BASE_ID="app6nKJvmX9gT0ENu"
3+
TABLE_ID="tbl0vTn0brhpL6k9g"
4+
VIEW="viwsti0b5uIN76xTu"
5+
HOMEPAGE_FIELD_ORDER="LedeImage,Category,Name,Dek,Author"
6+
FIELD_ORDER="LedeImage,Category,Name,Dek,Author,Body"
7+
HEADER_TITLE="TRACK CHANGES"
8+
PAGE_TITLE_COLUMN="Name"
9+
SITE_TITLE="TRACK CHANGES"
10+
MARKDOWN_FIELDS="Name,Body"
11+
SITE_DESCRIPTION="Welcome to Track Changes, Postlight's official publication and podcast covering the forces shaping technology today."

examples/roni-rony-rone/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-react"]
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": ["airbnb", "prettier"],
3+
"env": {
4+
"browser": true
5+
},
6+
"rules": {
7+
"no-underscore-dangle": 0,
8+
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
9+
}
10+
}

examples/roni-rony-rone/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v10.16

examples/roni-rony-rone/build.js

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/* eslint-disable no-console */
2+
3+
import formatAirtableRowData from "./src/utils/formatAirtableRowData";
4+
5+
require("dotenv").config();
6+
7+
const React = require("react");
8+
const fs = require("fs");
9+
const Airtable = require("airtable");
10+
const https = require("https");
11+
12+
const trimFieldOrder = require("./src/utils/trimFieldOrder");
13+
const Index = require("./src/components/Index").default;
14+
const RowPage = require("./src/components/RowPage").default;
15+
const tableHasPublishedColumn = require("./src/utils/tableHasPublishedColumn")
16+
.default;
17+
18+
process.env.FIELD_ORDER = trimFieldOrder(process.env.FIELD_ORDER);
19+
process.env.HOMEPAGE_FIELD_ORDER = trimFieldOrder(
20+
process.env.HOMEPAGE_FIELD_ORDER
21+
);
22+
23+
const renderAsHTMLPage = require(`./src/utils/renderAsHTMLPage`).default;
24+
25+
const { AIRTABLE_API_KEY, BASE_ID, TABLE_ID, VIEW } = process.env;
26+
27+
const base = new Airtable({ apiKey: AIRTABLE_API_KEY }).base(BASE_ID);
28+
29+
const allRows = [[]];
30+
31+
const downloadFile = (url, filepath, onSuccess, onError) => {
32+
const file = fs.createWriteStream(filepath);
33+
https
34+
.get(url, response => {
35+
response.pipe(file);
36+
file.on("finish", () => {
37+
file.close();
38+
onSuccess && onSuccess();
39+
});
40+
})
41+
.on("error", fileErr => {
42+
console.log(fileErr);
43+
fs.unlink(filepath, error => onError && onError(error));
44+
});
45+
};
46+
47+
// used to make sure multiple pages aren't created for same slug
48+
const alreadySeenSlugs = {};
49+
50+
const alreadyDownloadedAttachments = {};
51+
52+
let currentPage = 0;
53+
let recordsOnCurrentPage = 0;
54+
tableHasPublishedColumn(base, includePublished =>
55+
base(TABLE_ID)
56+
.select({
57+
view: VIEW,
58+
...(includePublished ? { filterByFormula: "{Published}" } : {})
59+
})
60+
.eachPage(
61+
function page(records, fetchNextPage) {
62+
records.forEach(row => {
63+
if (!allRows[currentPage]) {
64+
allRows.push([]);
65+
}
66+
const formattedRow = formatAirtableRowData(row);
67+
68+
const attachmentFields = formattedRow.fields.filter(
69+
field =>
70+
Array.isArray(field.value) &&
71+
field.value[0] &&
72+
field.value[0].size
73+
);
74+
75+
attachmentFields.forEach(attachmentField => {
76+
attachmentField.value.forEach(attachment => {
77+
if (!alreadyDownloadedAttachments[attachment.url]) {
78+
const newUrl = `/assets/${attachment.id}-${attachment.filename}`;
79+
downloadFile(attachment.url, `dist${newUrl}`);
80+
alreadyDownloadedAttachments[attachment.url] = true;
81+
attachment.url = newUrl;
82+
}
83+
});
84+
});
85+
86+
const slugFieldValue = row.fields.Slug;
87+
const slug =
88+
slugFieldValue !== undefined && !alreadySeenSlugs[slugFieldValue]
89+
? slugFieldValue
90+
: formattedRow.id;
91+
alreadySeenSlugs[slug] = true;
92+
93+
const pageTitle = row.fields[process.env.PAGE_TITLE_COLUMN];
94+
95+
const filepath = `dist/${slug}.html`;
96+
allRows[currentPage].push(formattedRow);
97+
recordsOnCurrentPage += 1;
98+
if (recordsOnCurrentPage >= 10) {
99+
recordsOnCurrentPage = 0;
100+
currentPage += 1;
101+
}
102+
103+
// write individual resource page files
104+
fs.writeFile(
105+
filepath,
106+
renderAsHTMLPage(<RowPage rowData={formattedRow} />, pageTitle),
107+
error => {
108+
if (error) {
109+
console.error(`Error writing ${filepath}`);
110+
} else {
111+
console.log(`${filepath} written`);
112+
}
113+
}
114+
);
115+
});
116+
117+
// calls page function again while there are still pages left
118+
fetchNextPage();
119+
},
120+
err => {
121+
if (err) {
122+
console.log(err);
123+
}
124+
125+
const writeFile = (idx, filepath, pagination) =>
126+
fs.writeFile(
127+
filepath,
128+
renderAsHTMLPage(
129+
<Index rows={allRows[idx]} pagination={pagination} />
130+
),
131+
error => {
132+
if (error) {
133+
console.error(`Error writing ${filepath}`);
134+
}
135+
}
136+
);
137+
138+
allRows.forEach((row, idx) => {
139+
const pageFilepath = `dist/page/${idx + 1}.html`;
140+
const indexFilepath = `dist/index.html`;
141+
const pagination = {
142+
back: idx > 0 ? `/page/${idx}.html` : null,
143+
next: idx < allRows.length - 1 ? `/page/${idx + 2}.html` : null
144+
};
145+
if (idx === 0) {
146+
// write index page at /
147+
writeFile(idx, indexFilepath, pagination);
148+
}
149+
// write page files for pagination
150+
writeFile(idx, pageFilepath, pagination);
151+
});
152+
}
153+
)
154+
);
155+
156+
fs.copyFile("public/default.css", "dist/main.css", () =>
157+
fs.readFile("custom/styles.css", "utf-8", (err, data) => {
158+
fs.writeFile("dist/main.css", data, { flag: "a" }, error => {
159+
if (error) {
160+
console.error("Error writing custom CSS to dist/main.css");
161+
} else {
162+
console.log("custom CSS appended to /dist/main.css");
163+
}
164+
});
165+
})
166+
);
167+
168+
fs.copyFile("custom/favicon.ico", "dist/favicon.ico", err => {
169+
if (err) {
170+
console.log("No favicon.ico file found");
171+
}
172+
});
14.7 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from "react";
2+
3+
const Author = ({ value, name }) => {
4+
const authors = value.join(", ");
5+
return (
6+
<div className="Author">
7+
<p>An Investigation by {authors}</p>
8+
</div>
9+
);
10+
};
11+
12+
export default Author;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from "react";
2+
3+
const GoogleMap = ({ value, name }) => {
4+
return (
5+
<div
6+
className={name.replace(" ", "")}
7+
dangerouslySetInnerHTML={{ __html: value }}
8+
/>
9+
);
10+
};
11+
12+
export default GoogleMap;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from "react";
2+
3+
const LedeImage = attachment => {
4+
const src = attachment.value[0].url;
5+
return (
6+
<div className="LedeImage" style={{ backgroundImage: `url(${src})` }} />
7+
);
8+
};
9+
10+
export default LedeImage;

0 commit comments

Comments
 (0)