PageEdit.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <footer class="page-edit">
  3. <div class="edit-link" v-if="editLink">
  4. <a :href="editLink" target="_blank" rel="noopener noreferrer">{{ editLinkText }}</a>
  5. <OutboundLink />
  6. </div>
  7. <div class="last-updated" v-if="lastUpdated">
  8. <span class="prefix">{{ lastUpdatedText }}:</span>
  9. <span class="time">{{ lastUpdated }}</span>
  10. </div>
  11. </footer>
  12. </template>
  13. <script>
  14. import isNil from 'lodash/isNil'
  15. import { endingSlashRE, outboundRE } from '../util'
  16. export default {
  17. name: 'PageEdit',
  18. computed: {
  19. lastUpdated () {
  20. return this.$page.lastUpdated
  21. },
  22. lastUpdatedText () {
  23. if (typeof this.$themeLocaleConfig.lastUpdated === 'string') {
  24. return this.$themeLocaleConfig.lastUpdated
  25. }
  26. if (typeof this.$site.themeConfig.lastUpdated === 'string') {
  27. return this.$site.themeConfig.lastUpdated
  28. }
  29. return 'Last Updated'
  30. },
  31. editLink () {
  32. const showEditLink = isNil(this.$page.frontmatter.editLink)
  33. ? this.$site.themeConfig.editLinks
  34. : this.$page.frontmatter.editLink
  35. const {
  36. repo,
  37. docsDir = '',
  38. docsBranch = 'master',
  39. docsRepo = repo
  40. } = this.$site.themeConfig
  41. if (showEditLink && docsRepo && this.$page.relativePath) {
  42. return this.createEditLink(
  43. repo,
  44. docsRepo,
  45. docsDir,
  46. docsBranch,
  47. this.$page.relativePath
  48. )
  49. }
  50. return null
  51. },
  52. editLinkText () {
  53. return (
  54. this.$themeLocaleConfig.editLinkText
  55. || this.$site.themeConfig.editLinkText
  56. || `Edit this page`
  57. )
  58. }
  59. },
  60. methods: {
  61. createEditLink (repo, docsRepo, docsDir, docsBranch, path) {
  62. const bitbucket = /bitbucket.org/
  63. if (bitbucket.test(repo)) {
  64. const base = outboundRE.test(docsRepo) ? docsRepo : repo
  65. return (
  66. base.replace(endingSlashRE, '')
  67. + `/src`
  68. + `/${docsBranch}/`
  69. + (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '')
  70. + path
  71. + `?mode=edit&spa=0&at=${docsBranch}&fileviewer=file-view-default`
  72. )
  73. }
  74. const base = outboundRE.test(docsRepo)
  75. ? docsRepo
  76. : `https://github.com/${docsRepo}`
  77. return (
  78. base.replace(endingSlashRE, '')
  79. + `/edit`
  80. + `/${docsBranch}/`
  81. + (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '')
  82. + path
  83. )
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="stylus">
  89. @require '../styles/wrapper.styl'
  90. .page-edit
  91. @extend $wrapper
  92. padding-top 1rem
  93. padding-bottom 1rem
  94. overflow auto
  95. .edit-link
  96. display inline-block
  97. a
  98. color lighten($textColor, 25%)
  99. margin-right 0.25rem
  100. .last-updated
  101. float right
  102. font-size 0.9em
  103. .prefix
  104. font-weight 500
  105. color lighten($textColor, 25%)
  106. .time
  107. font-weight 400
  108. color #aaa
  109. @media (max-width: $MQMobile)
  110. .page-edit
  111. .edit-link
  112. margin-bottom 0.5rem
  113. .last-updated
  114. font-size 0.8em
  115. float none
  116. text-align left
  117. </style>