Skip to content

Commit 31e10f4

Browse files
committed
feat(website): recently added packages widget
1 parent 73c8adc commit 31e10f4

File tree

8 files changed

+161
-84
lines changed

8 files changed

+161
-84
lines changed

docs/.vuepress/config.js

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ module.exports = {
150150
* Apply plugins,ref:https://v1.vuepress.vuejs.org/zh/plugin/
151151
*/
152152
plugins: [
153+
[
154+
"@vuepress/plugin-register-components",
155+
{
156+
componentsDir: path.resolve(__dirname, "./theme/components")
157+
}
158+
],
153159
"@vuepress/plugin-back-to-top",
154160
// ["@vuepress/pwa", { serviceWorker: true, updatePopup: true }],
155161
"@vuepress/plugin-medium-zoom",

docs/.vuepress/plugins/openupm-packages/index.js

+90-79
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
} = require("../../../../app/utils/package");
1414

1515
const readFile = util.promisify(fs.readFile);
16+
const pluginData = {};
1617

1718
// eslint-disable-next-line no-unused-vars
1819
module.exports = function(options, context) {
@@ -21,12 +22,14 @@ module.exports = function(options, context) {
2122
name: "openupm-packages",
2223

2324
async extendPageData($page) {
24-
let packageNames = await loadPackageNames();
25-
$page.packageCount = packageNames.length;
25+
const data = await plugin.getData();
26+
$page.packageCount = data.packageNames.length;
27+
$page.recentPackages = data.packages.slice(0, 10);
2628
},
2729

2830
async additionalPages() {
2931
const data = await plugin.getData();
32+
pluginData.data = data;
3033
let pages = [];
3134
pages = pages.concat(await plugin.genListPages(data));
3235
pages = pages.concat(await plugin.genDetailPages(data));
@@ -39,83 +42,91 @@ module.exports = function(options, context) {
3942

4043
// Prepare data for page generation
4144
async getData() {
42-
// Load packages.
43-
const packageNames = await loadPackageNames();
44-
const packages = packageNames
45-
.map(loadPackageSync)
46-
.filter(x => x)
47-
.map(pkg => {
48-
return {
49-
...pkg,
50-
link: {
51-
link: `/packages/${pkg.name}/`,
52-
text: pkg.displayName || pkg.name
53-
}
54-
};
55-
})
56-
// Sort by name
57-
.sort(function(a, b) {
58-
const va = a.link.text.toLowerCase();
59-
const vb = b.link.text.toLowerCase();
60-
if (va < vb) return -1;
61-
if (va > vb) return 1;
62-
return 0;
63-
});
64-
// Namespace => [package...] dict.
65-
const packageByNamespace = _.groupBy(packages, x => getNamespace(x.name));
66-
// Load topics.
67-
const topicsWithAll = [{ name: "All", slug: "" }]
68-
.concat((await loadTopics()).topics)
69-
.map(topic => {
70-
return {
71-
...topic,
72-
link: topic.slug ? `/packages/topics/${topic.slug}/` : "/packages/",
73-
count: packages.filter(pkg =>
74-
plugin.packageTopicFilter(pkg, topic.slug)
75-
).length
76-
};
77-
});
78-
const topics = topicsWithAll.slice(1);
79-
// contributors
80-
const getConstributors = function(type) {
81-
const entries = _.flatMap(packages, pkg => {
82-
if (type == "hunter") return [pkg.hunter];
83-
else if (type == "owner") {
84-
let arr = [pkg.owner];
85-
if (
86-
pkg.parentOwner &&
87-
pkg.parentOwnerUrl.toLowerCase().includes("github")
88-
)
89-
arr.push(pkg.parentOwner);
90-
return arr;
91-
} else return [];
92-
}).filter(x => x && x != "-");
93-
const counted = _.countBy(entries);
94-
const pairs = _.toPairs(counted).map(x => ({
95-
user: x[0],
96-
count: x[1]
97-
}));
98-
return _.sortBy(pairs, "count").reverse();
99-
};
100-
// Package hunters
101-
const hunters = getConstributors("hunter");
102-
const owners = getConstributors("owner");
103-
// Backers
104-
const backerPath = path.resolve(
105-
__dirname,
106-
"../../../../data/backers.yml"
107-
);
108-
const backers = yaml.safeLoad(await readFile(backerPath, "utf8"));
109-
return {
110-
backers,
111-
packageNames,
112-
packages,
113-
packageByNamespace,
114-
topics,
115-
topicsWithAll,
116-
hunters,
117-
owners
118-
};
45+
if (!pluginData.data) {
46+
// Load packages.
47+
const packageNames = await loadPackageNames();
48+
const packages = packageNames
49+
.map(loadPackageSync)
50+
.filter(x => x)
51+
.map(pkg => {
52+
return {
53+
...pkg,
54+
link: {
55+
link: `/packages/${pkg.name}/`,
56+
text: pkg.displayName || pkg.name
57+
}
58+
};
59+
})
60+
// Sort by name
61+
.sort(function(a, b) {
62+
const va = a.link.text.toLowerCase();
63+
const vb = b.link.text.toLowerCase();
64+
if (va < vb) return -1;
65+
if (va > vb) return 1;
66+
return 0;
67+
});
68+
// Namespace => [package...] dict.
69+
const packageByNamespace = _.groupBy(packages, x =>
70+
getNamespace(x.name)
71+
);
72+
// Load topics.
73+
const topicsWithAll = [{ name: "All", slug: "" }]
74+
.concat((await loadTopics()).topics)
75+
.map(topic => {
76+
return {
77+
...topic,
78+
link: topic.slug
79+
? `/packages/topics/${topic.slug}/`
80+
: "/packages/",
81+
count: packages.filter(pkg =>
82+
plugin.packageTopicFilter(pkg, topic.slug)
83+
).length
84+
};
85+
});
86+
const topics = topicsWithAll.slice(1);
87+
// contributors
88+
const getConstributors = function(type) {
89+
const entries = _.flatMap(packages, pkg => {
90+
if (type == "hunter") return [pkg.hunter];
91+
else if (type == "owner") {
92+
let arr = [pkg.owner];
93+
if (
94+
pkg.parentOwner &&
95+
pkg.parentOwnerUrl.toLowerCase().includes("github")
96+
)
97+
arr.push(pkg.parentOwner);
98+
return arr;
99+
} else return [];
100+
}).filter(x => x && x != "-");
101+
const counted = _.countBy(entries);
102+
const pairs = _.toPairs(counted).map(x => ({
103+
user: x[0],
104+
count: x[1]
105+
}));
106+
return _.sortBy(pairs, "count").reverse();
107+
};
108+
// Package hunters
109+
const hunters = getConstributors("hunter");
110+
const owners = getConstributors("owner");
111+
// Backers
112+
const backerPath = path.resolve(
113+
__dirname,
114+
"../../../../data/backers.yml"
115+
);
116+
const backers = yaml.safeLoad(await readFile(backerPath, "utf8"));
117+
// eslint-disable-next-line require-atomic-updates
118+
pluginData.data = {
119+
backers,
120+
packageNames,
121+
packages,
122+
packageByNamespace,
123+
topics,
124+
topicsWithAll,
125+
hunters,
126+
owners
127+
};
128+
}
129+
return pluginData.data;
119130
},
120131

121132
// Generate package list pages
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!-- eslint-disable vue/no-v-html -->
2+
<template>
3+
<div class="package-recent container">
4+
<div class="columns">
5+
<div class="column col-12 col-sm-12">
6+
<div class="columns">
7+
<div
8+
v-for="pkg in packages"
9+
:key="pkg.id"
10+
class="column col-4 col-md-6 col-sm-12"
11+
>
12+
<PackageCard :item="pkg" :show-created-at="true" />
13+
</div>
14+
</div>
15+
</div>
16+
</div>
17+
</div>
18+
</template>
19+
20+
<script>
21+
import _ from "lodash";
22+
import PackageCard from "@theme/components/PackageCard.vue";
23+
24+
export default {
25+
components: { PackageCard },
26+
props: {
27+
count: {
28+
type: Number,
29+
default: 3
30+
}
31+
},
32+
data() {
33+
return {};
34+
},
35+
computed: {
36+
packages() {
37+
const pkgs = this.$page.recentPackages;
38+
return _.orderBy(pkgs, ["createdAt"], ["desc"]).slice(0, this.count);
39+
}
40+
}
41+
};
42+
</script>
43+
44+
<style lang="stylus">
45+
.package-recent
46+
margin-top 1rem
47+
</style>

docs/.vuepress/theme/layouts/Home.vue

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default {
7373
.home
7474
.hero
7575
padding-top 5.5rem
76-
padding-bottom 4rem
76+
padding-bottom 2rem
7777
7878
.hero-body
7979
text-align center
@@ -88,11 +88,14 @@ export default {
8888
margin-right 1rem
8989
9090
.features
91-
margin-bottom 4rem
91+
margin-bottom 3rem
9292
h3
9393
font-size 1.1rem
9494
color $accentColor
9595
96+
h3
97+
margin-top 2rem
98+
9699
.social-share
97100
text-align center
98101
margin-bottom 1rem
@@ -113,6 +116,11 @@ export default {
113116
.social-share
114117
margin-bottom 0.4rem
115118
119+
.package-recent
120+
margin-left -1rem
121+
margin-right -1rem
122+
width calc(100% + 2rem)
123+
116124
.warning.custom-block
117-
margin: 0 -1rem
125+
margin: 0 -1rem !important
118126
</style>

docs/.vuepress/theme/layouts/PackageList.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<div
5858
v-for="pkg in packages"
5959
:key="pkg.id"
60-
class="column col-6 col-md-12 tile-wrap"
60+
class="column col-6 col-md-12"
6161
>
6262
<PackageCard
6363
:item="pkg"
@@ -78,7 +78,7 @@
7878
import _ from "lodash";
7979
import ParentLayout from "@theme/layouts/Layout.vue";
8080
import NavLink from "@parent-theme/components/NavLink.vue";
81-
import PackageCard from "@theme/layouts/PackageCard.vue";
81+
import PackageCard from "@theme/components/PackageCard.vue";
8282

8383
export default {
8484
components: { ParentLayout, NavLink, PackageCard },

docs/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ manifest updated, please open unity project to apply changes
4343
openupm-cli requires [Node.js 12](https://nodejs.org/en/)
4444
:::
4545

46+
### Recent Packages
47+
48+
<PackageRecent />
49+
4650
<social-share />

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@vuepress/plugin-google-analytics": "^1.2.0",
3030
"@vuepress/plugin-medium-zoom": "^1.0.0",
3131
"@vuepress/plugin-pwa": "^1.2.0",
32+
"@vuepress/plugin-register-components": "^1.2.0",
3233
"axios": "^0.19.0",
3334
"babel-eslint": "^10.0.3",
3435
"change-case": "^4.1.0",

0 commit comments

Comments
 (0)