commits.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 { createApp, ref, watchEffect } = Vue
  33. const API_URL = `https://api.github.com/repos/vuejs/core/commits?per_page=3&sha=`
  34. const truncate = v => {
  35. const newline = v.indexOf('\n')
  36. return newline > 0 ? v.slice(0, newline) : v
  37. }
  38. const formatDate = v => v.replace(/T|Z/g, ' ')
  39. createApp({
  40. setup() {
  41. const currentBranch = ref('main')
  42. const commits = ref(null)
  43. watchEffect(() => {
  44. fetch(`${API_URL}${currentBranch.value}`)
  45. .then(res => res.json())
  46. .then(data => {
  47. console.log(data)
  48. commits.value = data
  49. })
  50. })
  51. return {
  52. branches: ['main', 'v2-compat'],
  53. currentBranch,
  54. commits,
  55. truncate,
  56. formatDate,
  57. }
  58. },
  59. }).mount('#demo')
  60. </script>
  61. <style>
  62. #demo {
  63. font-family: 'Helvetica', Arial, sans-serif;
  64. }
  65. a {
  66. text-decoration: none;
  67. color: #f66;
  68. }
  69. li {
  70. line-height: 1.5em;
  71. margin-bottom: 20px;
  72. }
  73. .author,
  74. .date {
  75. font-weight: bold;
  76. }
  77. </style>