Skip to content

Commit

Permalink
chore: build sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Apr 18, 2022
1 parent 1dee4e8 commit eb653a4
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
10 changes: 10 additions & 0 deletions BACKERS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Backers

<!-- SPONSORS_TABLE_WRAP -->
<table>
<tr>
<td align="center" valign="middle">
Expand Down Expand Up @@ -130,6 +131,7 @@
<td></td>
</tr>
</table>
<!-- SPONSORS_TABLE_WRAP -->

Support Framework7 development by [pledging on Patreon](https://www.patreon.com/framework7)!

Expand All @@ -155,16 +157,22 @@ Support Framework7 development by [pledging on Patreon](https://www.patreon.com/

### \$100 Silver Sponsor

<!-- SILVER_SPONSOR -->

[Ramotion](https://www.ramotion.com/agency/app-development/) - App Development Agency<br>
[Thorium Builder](https://www.thoriumbuilder.com/) - Full visual Framework7 app builder<br>
Mason Fok ([tommy](http://mytommy.com))<br>

<!-- SILVER_SPONSOR -->

[Join here!](https://www.patreon.com/bePatron?patAmt=100.0&exp=1&u=4109762&rid=830841)

---

### \$50+ Top Supporter

<!-- TOP_SUPPORTER -->

[CodeFirst](https://www.codefirst.co.uk) - Software Development Company | CodeFirst UK<br>
[Buy Instagram Likes from Goread](https://goread.io/buy-instagram-likes)<br>
[Coupons4Printing: Promotion Codes, Coupons, Coupon Codes](https://www.coupons4printing.com)<br>
Expand All @@ -187,6 +195,8 @@ Bearr Dayss<br>
Kris Reddy<br>
Bart DJ

<!-- TOP_SUPPORTER -->

[Join here!](https://www.patreon.com/bePatron?exp=1&rid=830842&u=4109762&patAmt=50.0)

---
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Framework7 is an MIT-licensed open source project with its ongoing development m

<h3 align="center">Sponsors</h3>

<!-- SPONSORS_TABLE_WRAP -->
<table>
<tr>
<td align="center" valign="middle">
Expand Down Expand Up @@ -146,6 +147,7 @@ Framework7 is an MIT-licensed open source project with its ongoing development m
<td></td>
</tr>
</table>
<!-- SPONSORS_TABLE_WRAP -->

## Getting Started

Expand Down
148 changes: 148 additions & 0 deletions scripts/build-sponsors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
const fs = require('fs');
const path = require('path');
const https = require('https');

const getSponsors = () => {
let sponsorsLocal;
try {
const localPath = path.resolve(__dirname, '../../framework7-website/src/pug/sponsors.json');
if (fs.existsSync(localPath)) {
// eslint-disable-next-line
sponsorsLocal = require(localPath);
}
} catch (err) {
// error
}
if (sponsorsLocal) return sponsorsLocal;

return new Promise((resolve, reject) => {
https
.get('https://framework7.io/sponsors/sponsors.json', (resp) => {
let data = '';

// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk;
});

// The whole response has been received. Print out the result.
resp.on('end', () => {
resolve(JSON.parse(data));
});
})
.on('error', (err) => {
reject(err);
});
});
};

const buildTables = (sponsors) => {
const tableSponsors = [
...(sponsors.diamondSponsor || []),
...(sponsors.platinumSponsor || []),
...(sponsors.goldSponsor || []),
...(sponsors.silverSponsor || []),
...(sponsors.topSupporter || []),
];

let tableContent = '';
if (tableSponsors.length > 0) {
const rows = [];
const perRow = 8;
let rowIndex = 0;

tableSponsors.forEach((item, index) => {
const colIndex = index - perRow * rowIndex;
if (colIndex > perRow - 1) rowIndex += 1;
if (!rows[rowIndex]) rows[rowIndex] = [];
rows[rowIndex].push(item);
});
if (rows.length > 0 && rows[rows.length - 1].length < perRow) {
rows[rows.length - 1].push(...Array.from({ length: perRow - rows[rows.length - 1].length }));
}
tableContent = `\n<table>\n${rows
.map((items) =>
[
` <tr>`,
items
.map((item) =>
!item
? ' <td align="center" valign="middle"></td>'
: [
` <td align="center" valign="middle">`,
` <a href="${item.link}" target="_blank">`,
` <img src="https://framework7.io/i/sponsors/${item.image}" alt="${item.title}" width="160">`,
` </a>`,
` </td>`,
].join('\n'),
)
.join('\n'),
` </tr>`,
].join('\n'),
)
.join('\n')}\n</table>\n`;
}

const backersContent = fs
.readFileSync(path.resolve(__dirname, '../BACKERS.md'), 'utf-8')
.split('<!-- SPONSORS_TABLE_WRAP -->');
backersContent[1] = tableContent;

const readmeContent = fs
.readFileSync(path.resolve(__dirname, '../README.md'), 'utf-8')
.split('<!-- SPONSORS_TABLE_WRAP -->');
readmeContent[1] = tableContent;

fs.writeFileSync(
path.resolve(__dirname, '../BACKERS.md'),
backersContent.join('<!-- SPONSORS_TABLE_WRAP -->'),
);

fs.writeFileSync(
path.resolve(__dirname, '../README.md'),
readmeContent.join('<!-- SPONSORS_TABLE_WRAP -->'),
);
};

const buildSponsorsList = async (sponsors) => {
const silverSponsorsContent = sponsors.silverSponsor.map((item) =>
`
- [${item.title}](${item.link})
`.trim(),
);
const topSupportersContent = sponsors.topSupporter.map((item) =>
`
- [${item.title}](${item.link})
`.trim(),
);

let backersContent = fs.readFileSync(path.resolve(__dirname, '../BACKERS.md'), 'utf-8');

backersContent = backersContent.split('<!-- SILVER_SPONSOR -->');
backersContent[1] = `\n${silverSponsorsContent.join('\n')}\n`;
backersContent = backersContent.join('<!-- SILVER_SPONSOR -->');

backersContent = backersContent.split('<!-- TOP_SUPPORTER -->');
backersContent[1] = `\n${topSupportersContent.join('\n')}\n`;
backersContent = backersContent.join('<!-- TOP_SUPPORTER -->');

fs.writeFileSync(path.resolve(__dirname, '../BACKERS.md'), backersContent);
};

const buildSponsors = async () => {
const entries = await getSponsors();
const sponsors = {};

if (entries) {
Object.keys(entries).forEach((plan) => {
entries[plan] = entries[plan].sort((a, b) => {
return new Date(a.createdAt) > new Date(b.createdAt) ? -1 : 1;
});
});
}

buildTables(sponsors);
buildSponsorsList(sponsors);
};

buildSponsors();

0 comments on commit eb653a4

Please sign in to comment.