| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import React from 'react';
- import PropTypes from 'prop-types';
- import path from 'path';
- export default class PublishLink extends React.PureComponent {
- constructor(props) {
- super(props);
- this.state = {
- linker: '',
- };
- this.generateLink = this.generateLink.bind(this);
- }
- generateLink() {
- const {
- link,
- label,
- type,
- isUseRelativePath,
- currentPagePath,
- } = this.props;
- let linker;
- let reshapedLink = link;
- if (isUseRelativePath && link.match(/^\//)) {
- reshapedLink = path.relative(currentPagePath, link);
- }
- if (type === 'pukiwikiLink') {
- linker = `[[${label}>${reshapedLink}]]`;
- }
- if (type === 'growiLink') {
- linker = `[${reshapedLink}]`;
- }
- if (type === 'mdLink') {
- linker = `[${label}](${reshapedLink})`;
- }
- this.setState({ linker });
- }
- render() {
- this.generateLink();
- return (
- <input type="text" readOnly className="form-control-plaintext" id="staticEmail" value={this.state.linker}></input>
- );
- }
- }
- PublishLink.propTypes = {
- link: PropTypes.string.isRequired,
- label: PropTypes.string,
- type: PropTypes.oneOf(['pukiwikiLink', 'growiLink', 'mdLink']).isRequired,
- isUseRelativePath: PropTypes.bool,
- currentPagePath: PropTypes.string,
- };
|