commits.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <script src="../../dist/vue.global.js"></script>
  2. <div id="demo">
  3. <h1>Latest Vue.js Commits</h1>
  4. <template v-for="branch in branches">
  5. <input
  6. type="radio"
  7. :id="branch"
  8. :value="branch"
  9. name="branch"
  10. v-model="currentBranch"
  11. />
  12. <label :for="branch">{{ branch }}</label>
  13. </template>
  14. <p>vuejs/core@{{ currentBranch }}</p>
  15. <ul>
  16. <li v-for="{ html_url, sha, author, commit } in commits">
  17. <a :href="html_url" target="_blank" class="commit"
  18. >{{ sha.slice(0, 7) }}</a
  19. >
  20. - <span class="message">{{ truncate(commit.message) }}</span><br />
  21. by
  22. <span class="author"
  23. ><a :href="author.html_url" target="_blank"
  24. >{{ commit.author.name }}</a
  25. ></span
  26. >
  27. at <span class="date">{{ formatDate(commit.author.date) }}</span>
  28. </li>
  29. </ul>
  30. </div>
  31. <script>
  32. const API_URL = `https://api.github.com/repos/vuejs/core/commits?per_page=3&sha=`
  33. Vue.createApp({
  34. data: () => ({
  35. branches: ['main', 'v2-compat'],
  36. currentBranch: 'main',
  37. commits: null,
  38. }),
  39. created() {
  40. this.fetchData()
  41. },
  42. watch: {
  43. currentBranch: 'fetchData',
  44. },
  45. methods: {
  46. fetchData() {
  47. fetch(`${API_URL}${this.currentBranch}`)
  48. .then(res => res.json())
  49. .then(data => {
  50. this.commits = data
  51. })
  52. },
  53. truncate(v) {
  54. const newline = v.indexOf('\n')
  55. return newline > 0 ? v.slice(0, newline) : v
  56. },
  57. formatDate(v) {
  58. return v.replace(/T|Z/g, ' ')
  59. },
  60. },
  61. }).mount('#demo')
  62. </script>
  63. <style>
  64. #demo {
  65. font-family: 'Helvetica', Arial, sans-serif;
  66. }
  67. a {
  68. text-decoration: none;
  69. color: #f66;
  70. }
  71. li {
  72. line-height: 1.5em;
  73. margin-bottom: 20px;
  74. }
  75. .author,
  76. .date {
  77. font-weight: bold;
  78. }
  79. </style>