UNPKG

@hjkl6/dumi-theme-antv

Version:

[![NPM version](https://img.shields.io/npm/v/@antv/dumi-theme-antv.svg?style=flat)](https://npmjs.org/package/@antv/dumi-theme-antv) [![NPM downloads](http://img.shields.io/npm/dm/@antv/dumi-theme-antv.svg?style=flat)](https://npmjs.org/package/@antv/dumi

37 lines 1.44 kB
import { FormOutlined } from '@ant-design/icons'; import { useIntl, useRouteMeta, useSiteData } from 'dumi'; import path from 'path'; import React from 'react'; import { useGithubRepo } from "../../utils/github"; export var EditButton = function EditButton() { var meta = useRouteMeta(); var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useSiteData = useSiteData(), themeConfig = _useSiteData.themeConfig; var githubUrl = themeConfig.githubUrl, _themeConfig$sitePack = themeConfig.sitePackagePath, sitePackagePath = _themeConfig$sitePack === void 0 ? '/packages/site' : _themeConfig$sitePack; var _useGithubRepo = useGithubRepo(), defaultBranch = _useGithubRepo.defaultBranch; var editable = !meta.frontmatter.readonly; if (!editable) { return null; } var branchUrl = "".concat(githubUrl, "/edit/").concat(defaultBranch); var url = meta.frontmatter.redirect ? path.join(branchUrl, meta.frontmatter.redirect) : path.join(branchUrl, sitePackagePath, meta.frontmatter.filename || ''); return /*#__PURE__*/React.createElement("a", { onClick: function onClick() { return window.open(url, '_blank'); } }, /*#__PURE__*/React.createElement(FormOutlined, { style: { fontSize: 16, marginRight: 8 } }), /*#__PURE__*/React.createElement("span", { className: "button-text" }, formatMessage({ id: '在 GitHub 上编辑此页' }))); };