Skip to content

Commit 17e8335

Browse files
authored
Merge pull request #21 from ibelem/blog
Add blog - onnx2webnn
2 parents a78a1aa + 357e989 commit 17e8335

17 files changed

+711
-1
lines changed

app/_components/authors.jsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { getDictionary } from '../_dictionaries/get-dictionary'
2+
3+
export const TopContent = async ({ title, date, authors, lang }) => {
4+
const dictionary = await getDictionary(lang)
5+
const dateObj = new Date(date)
6+
return (
7+
<>
8+
<h1 className="x:tracking-tight x:text-slate-900 x:dark:text-slate-100 x:font-bold x:mt-2 x:text-4xl">{title}</h1>
9+
<div className="my-4 text-sm text-gray-400">
10+
<time dateTime={dateObj.toISOString()}>
11+
{dateObj.toLocaleDateString(lang, {
12+
month: 'long',
13+
day: 'numeric',
14+
year: 'numeric'
15+
})}
16+
</time>{' '}
17+
{dictionary.by}{' '}
18+
{authors.map(author => (
19+
<span key={author.name} className="not-last:after:content-[',_']">
20+
<a
21+
href={author.link}
22+
target="_blank"
23+
rel="noreferrer"
24+
className="text-gray-800 dark:text-gray-100"
25+
>
26+
{author.name}
27+
</a>
28+
</span>
29+
))}
30+
</div>
31+
</>
32+
)
33+
}

app/_components/blog.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Link } from 'nextra-theme-docs'
2+
import { getPageMap } from 'nextra/page-map'
3+
4+
export const Blog = async ({ lang }) => {
5+
const pageMap = await getPageMap(`/${lang}/blog`)
6+
return pageMap.map(page => {
7+
if (page.name === 'index') return
8+
const { title, description, date } = page.frontMatter
9+
10+
return (
11+
<div key={page.route} className="mt-12">
12+
<h3 className="text-2xl font-semibold"><Link href={page.route} className="">{title}</Link></h3>
13+
<p className="my-6 leading-7 opacity-80">
14+
{description}{' '}
15+
<Link href={page.route} className="after:content-['_→']">
16+
Read more
17+
</Link>
18+
</p>
19+
{date && !isNaN(new Date(date)) && (
20+
<time
21+
dateTime={new Date(date).toISOString()}
22+
className="text-sm opacity-50"
23+
>
24+
{new Date(date).toLocaleDateString(lang, {
25+
month: 'long',
26+
day: 'numeric',
27+
year: 'numeric'
28+
})}
29+
</time>
30+
)}
31+
</div>
32+
)
33+
})
34+
}

app/_components/video.jsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use client'
2+
3+
import { useCallback, useEffect, useRef } from 'react'
4+
import { useInView } from 'react-intersection-observer'
5+
6+
export const Video = ({ src, caption, ratio }) => {
7+
const [inViewRef, inView] = useInView({ threshold: 1 })
8+
const videoRef = useRef(null)
9+
10+
const setRefs = useCallback(
11+
(node) => {
12+
// Ref's from useRef needs to have the node assigned to `current`
13+
videoRef.current = node
14+
// Callback refs, like the one from `useInView`, is a function that takes the node as an argument
15+
inViewRef(node)
16+
17+
node.addEventListener('click', function () {
18+
if (this.paused) {
19+
this.play()
20+
} else {
21+
this.pause()
22+
}
23+
})
24+
},
25+
[inViewRef]
26+
)
27+
28+
useEffect(() => {
29+
if (!videoRef.current) {
30+
return
31+
}
32+
33+
if (inView) {
34+
videoRef.current.play()
35+
} else {
36+
videoRef.current.pause()
37+
}
38+
}, [inView])
39+
40+
return (
41+
<div style={{ position: 'relative', margin: '2rem 1rem' }}>
42+
<div style={{ paddingBottom: ratio * 100 + '%' }} />
43+
<video
44+
style={{ position: 'absolute', top: 0, left: 0 }}
45+
loop
46+
muted
47+
autoPlay
48+
playsInline
49+
ref={setRefs}
50+
>
51+
<source src={src} type="video/mp4" />
52+
</video>
53+
{caption && (
54+
<figcaption style={{ fontSize: '.9rem', textAlign: 'center' }}>
55+
{caption}
56+
</figcaption>
57+
)}
58+
</div>
59+
)
60+
}

app/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ h5 {
168168
color: var(--n-1);
169169
background-color: var(--dark-bg);
170170
border-radius: 5px;
171-
padding: 0 0.4rem;
171+
padding: 0.2rem 0.6rem;
172172
}
173173

174174
.light h3:hover .x\:text-primary-600 {

content/en/_meta.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export default {
2222
title: 'FAQ',
2323
type: 'page',
2424
},
25+
blog: {
26+
title: 'Blog',
27+
type: 'page',
28+
},
2529
showcase: {
2630
title: 'Showcase',
2731
type: 'page',

content/en/blog.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
searchable: true
3+
---
4+
5+
import { Blog } from '../../app/_components/blog'
6+
7+
# WebNN
8+
9+
<Blog lang={props.params.lang} />

0 commit comments

Comments
 (0)