Skip to content

Commit

Permalink
Closed #181
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Jul 28, 2024
1 parent ba772b3 commit 7ba09dc
Show file tree
Hide file tree
Showing 35 changed files with 1,416 additions and 1,372 deletions.
6 changes: 3 additions & 3 deletions packages/gem-book/docs/zh/003-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ yarn add gem-book
将内容插入 `<gem-book>`,这允许在特定页面自定义 `<gem-book>` 内容,例如自定义侧边栏:

```md
<gbp-content>
<div slot="sidebar-before">Test</div>
<gbp-content slot="sidebar-before">
<div>Test</div>
<style>
gem-book::part(sidebar-content) {
gem-book [part=sidebar-content] {
display: none;
}
</style>
Expand Down
2 changes: 1 addition & 1 deletion packages/gem-book/src/bin/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export async function buildApp(dir: string, options: Required<CliUniqueConfig>,
new CopyWebpackPlugin({
patterns: [{ from: docsDir, to: outputDir }],
}),
],
].filter((e) => !!e),
});
if (build) {
webpackCompiler.run((err, stats) => {
Expand Down
52 changes: 26 additions & 26 deletions packages/gem-book/src/element/elements/404.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { customElement, GemElement, html, shadow } from '@mantou/gem';
import { adoptedStyle, createCSSSheet, css, customElement, GemElement, html } from '@mantou/gem';

import { getGithubPath } from '../lib/utils';
import { bookStore, locationStore } from '../store';
Expand All @@ -11,8 +11,32 @@ import '@mantou/gem/elements/reflect';
import '@mantou/gem/elements/title';
import '@mantou/gem/elements/use';

const styles = createCSSSheet(css`
:scope {
text-align: center;
}
h1 {
font-size: 2em;
font-weight: bold;
margin: 0;
}
gem-link {
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
}
gem-link:hover {
opacity: 0.8;
}
gem-use {
width: 18px;
height: 18px;
margin-right: 10px;
}
`);
@customElement('gem-book-404')
@shadow()
@adoptedStyle(styles)
export class Meta extends GemElement {
#getMdFullPath = () => {
const { links = [] } = bookStore;
Expand All @@ -31,30 +55,6 @@ export class Meta extends GemElement {
const noGithub = !github || !sourceBranch || !fullPath;

return html`
<style>
:host {
text-align: center;
}
h1 {
font-size: 2em;
font-weight: bold;
margin: 0;
}
gem-link {
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
}
gem-link:hover {
opacity: 0.8;
}
gem-use {
width: 18px;
height: 18px;
margin-right: 10px;
}
</style>
<h1><gem-title inert>Not Found</gem-title></h1>
${noGithub
? ''
Expand Down
73 changes: 37 additions & 36 deletions packages/gem-book/src/element/elements/edit-link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, GemElement, customElement, connectStore, shadow } from '@mantou/gem';
import { html, GemElement, customElement, connectStore, css, adoptedStyle, createCSSSheet } from '@mantou/gem';
import { mediaQuery } from '@mantou/gem/helper/mediaquery';

import { getGithubPath } from '../lib/utils';
Expand All @@ -10,6 +10,41 @@ import { icons } from './icons';
import '@mantou/gem/elements/link';
import '@mantou/gem/elements/use';

const styles = createCSSSheet(css`
:scope {
display: flex;
gap: 1rem;
flex-wrap: wrap;
padding-block: 6rem 2rem;
box-sizing: border-box;
justify-content: space-between;
line-height: 1.5;
}
gem-link {
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
}
gem-link:hover {
opacity: 0.8;
}
gem-use {
width: 18px;
height: 18px;
margin-right: 10px;
}
.last-updated gem-link {
opacity: 0.5;
}
@media ${mediaQuery.PHONE} {
gem-link,
.last-updated {
white-space: nowrap;
}
}
`);

interface State {
lastUpdated: string;
message: string;
Expand All @@ -26,7 +61,7 @@ const fetchData = async (api: string) => {

@customElement('gem-book-edit-link')
@connectStore(locationStore)
@shadow()
@adoptedStyle(styles)
export class EditLink extends GemElement<State> {
state = {
lastUpdated: '',
Expand Down Expand Up @@ -62,40 +97,6 @@ export class EditLink extends GemElement<State> {
const { github, sourceBranch = '' } = config || {};
if (!github || !sourceBranch || !this.#fullPath) return;
return html`
<style>
:host {
display: flex;
gap: 1rem;
flex-wrap: wrap;
padding-block: 6rem 2rem;
box-sizing: border-box;
justify-content: space-between;
line-height: 1.5;
}
gem-link {
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
}
gem-link:hover {
opacity: 0.8;
}
gem-use {
width: 18px;
height: 18px;
margin-right: 10px;
}
.last-updated gem-link {
opacity: 0.5;
}
@media ${mediaQuery.PHONE} {
gem-link,
.last-updated {
white-space: nowrap;
}
}
</style>
<gem-link href=${`${github}/edit/${sourceBranch}${this.#fullPath}`}>
<gem-use .element=${icons.compose}></gem-use>
<span>${selfI18n.get('editOnGithub')}</span>
Expand Down
41 changes: 21 additions & 20 deletions packages/gem-book/src/element/elements/footer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, GemElement, customElement, connectStore, css, shadow } from '@mantou/gem';
import { html, GemElement, customElement, connectStore, css, createCSSSheet, adoptedStyle } from '@mantou/gem';

import { selfI18n } from '../helper/i18n';
import { theme } from '../helper/theme';
Expand All @@ -7,31 +7,32 @@ import { unsafeRenderHTML } from '../lib/renderer';

import '@mantou/gem/elements/link';

const styles = createCSSSheet(css`
:scope {
display: block;
padding-block: 2rem;
box-sizing: border-box;
border-top: 1px solid ${theme.borderColor};
font-style: italic;
line-height: 1.5;
color: rgb(from ${theme.textColor} r g b / 0.5);
}
gem-link {
color: ${theme.textColor};
text-decoration: none;
}
gem-link:hover {
opacity: 0.8;
}
`);

@customElement('gem-book-footer')
@connectStore(bookStore)
@shadow()
@adoptedStyle(styles)
export class Footer extends GemElement {
render() {
const { config } = bookStore;
return html`
<style>
:host {
display: block;
padding-block: 2rem;
box-sizing: border-box;
border-top: 1px solid ${theme.borderColor};
font-style: italic;
line-height: 1.5;
color: rgba(${theme.textColorRGB}, 0.5);
}
gem-link {
color: ${theme.textColor};
text-decoration: none;
}
gem-link:hover {
opacity: 0.8;
}
</style>
${config?.footer
? unsafeRenderHTML(
config.footer,
Expand Down
Loading

0 comments on commit 7ba09dc

Please sign in to comment.