<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      solitude組件wakatime編碼時長側邊欄

      本人博客原文
      https://www.konoxin.top/posts/82e0e7c7/

      前言

      最近想在博客引入waketime的編碼熱力圖,就研究了一下,

      效果是這樣的:

      首先你已經使用過wakatime,

      如果沒有起前往如下教程,

      {% link 'WakaTime的使用(vscode,idea,hbuilder)' 'WakaTime' 'https://juejin.cn/post/6981098690312142861' %}

      教程

      第一步

      接下來前往WakaTime的API文檔

      {% link 'WakaTime的API文檔' 'WakaTime' 'https://wakatime.com/share/embed' %}

      按照如下操作會得到json的接口

      第二步

      在source -> _data -> aside.yml (沒有就新建)

      下增加如下代碼

      - name: code
        title: 編碼時長
        class: card-code
        id:
        icon: fas fa-calendar-days
        content_id: code-info
        # content_css: 'height:160px;overflow:hidden'
        content_html: '<div class="codeTime"><div class="code" id="code"></div></div>
          <div class="legend">
              <div class="legend-item"><div class="legend-color" style="background: #ebedf0;"></div>無數據</div>
              <div class="legend-item"><div class="legend-color" style="background: #9be9a8;"></div>0-2小時</div>
              <div class="legend-item"><div class="legend-color" style="background: #40c463;"></div>2-4小時</div>
              <div class="legend-item"><div class="legend-color" style="background: #30a14e;"></div>4-6小時</div>
              <div class="legend-item"><div class="legend-color" style="background: #216e39;"></div>6+小時</div>
          </div>'
      
      

      然后在你的自定義入口 js 下輸入

      在source -> js -> 你的js (沒有就新建)

      在const response = await fetch('')引入你在wakatime得到的接口

      async function fetchData() {
        
          try {
              // 使用CORS代理
              const response = await fetch(`https://wakatime.com/xxx.json`);
              const data = await response.json();
              // 修正數據訪問路徑
              if (data) {
                  console.log('成功獲取數據,天數:', data.days.length);
                  return data.days;
              } else {
                  console.warn('數據格式不符合預期:', data);
                  return [];
              }
          } catch (error) {
              console.error('獲取數據失敗:', error);
              return [];
          }
      }
      
      function getColor(hours) {
          if (!hours || hours === 0) return '#ebedf0'; // 無數據或0小時顯示灰色
          if (hours < 2) return '#9be9a8'; // 0-2小時: 淺綠
          if (hours < 4) return '#40c463'; // 2-4小時: 中綠
          if (hours < 6) return '#30a14e'; // 4-6小時: 深綠
          return '#216e39'; // 6+小時: 最深綠
      }
      
      function renderCalendar(days) {
          const calendarEl = document.getElementById('code');
          const today = new Date();
          const startDate = new Date();
          startDate.setMonth(today.getMonth() - 11); // 顯示最近12個月
      
          let currentDate = new Date(startDate);
          let currentMonth = currentDate.getMonth();
      
          // 添加月份標簽
          // const monthLabel = document.createElement('div');
          // monthLabel.className = 'month-label';
          // monthLabel.textContent = currentDate.toLocaleString('zh-CN', { month: 'long' }) + ' ' + currentDate.getFullYear();
          // calendarEl.appendChild(monthLabel);
      
          // 跳過第一周的空白天數
          const firstDayOfWeek = currentDate.getDay();
          for (let i = 0; i < firstDayOfWeek; i++) {
              const emptyDay = document.createElement('div');
              emptyDay.className = 'day';
              emptyDay.style.visibility = 'hidden';
              calendarEl.appendChild(emptyDay);
          }
      
          while (currentDate <= today) {
              // 檢查是否需要添加新的月份標簽
              if (currentDate.getMonth() !== currentMonth) {
                  currentMonth = currentDate.getMonth();
                  // const monthLabel = document.createElement('div');
                  // monthLabel.className = 'month-label';
                  // monthLabel.textContent = currentDate.toLocaleString('zh-CN', { month: 'long' }) + ' ' + currentDate.getFullYear();
                  // calendarEl.appendChild(monthLabel);
              }
      
              const dateStr = currentDate.toISOString().split('T')[0];
              const dayData = days.find(d => d.date === dateStr);
              const hours = dayData ? dayData.total / 3600 : 0; // 使用total字段計算小時數
      
              const dayEl = document.createElement('div');
              dayEl.className = 'day';
              dayEl.style.backgroundColor = getColor(hours);
              dayEl.setAttribute('data-date', dateStr);
              dayEl.setAttribute('data-hours', hours.toFixed(1));
      
              calendarEl.appendChild(dayEl);
      
              currentDate.setDate(currentDate.getDate() + 1);
          }
      }
      
      (async function () {
      
          const data = await fetchData();
          renderCalendar(data);
      })();
      
      async function codeTime(){
          const data = await fetchData();
          renderCalendar(data);
      }
      function handlePjaxComplete() {
          if (isHomePage()) {
              codeTime()
          }
      }
      
      function isHomePage() {
          return window.location.pathname === '/' || window.location.pathname === '/index.html';
      }
      
      window.onload = function () {
          document.addEventListener("pjax:complete", handlePjaxComplete);
      }
      

      接下來在你的自定義入口 css 下輸入

      在source -> css -> 你的css (沒有就新建)

              .code {
                display: flex;
                flex-wrap: wrap;
                gap: 3px;
                margin-top: 7px;
              }
      
              .day {
                width: 10px;
                height: 10px;
                border-radius: 2px;
                background: #ebedf0;
                position: relative;
              }
      
              .day:hover::after {
                content: attr(data-date) " - " attr(data-hours) "小時";
                position: absolute;
                top: -30px;
                left: 50%;
                transform: translateX(-50%);
                background: #333;
                color: white;
                padding: 3px 6px;
                border-radius: 3px;
                font-size: 12px;
                white-space: nowrap;
                z-index: 100000;
        
              }
      
              .month-label {
                width: 100%;
                margin-top: 10px;
                font-size: 12px;
                color: #666;
              }
      
              .legend {
                margin-top: 5px;
                margin-bottom: 7px;
                display: flex;
                justify-content: space-between;
              }
      
              .legend-item {
                display: flex;
                align-items: center;
                font-size: 9px;
              }
      
              .legend-color {
                width: 12px;
                height: 12px;
                border-radius: 2px;
                margin-right: 5px;
              }
      

      最后修改你的 _config.solitude.yml 中的aside下的home新增code

      aside:
        # Values: about (info card), newestPost (latest article), allInfo (website information), newest_comment (latest comment)
        # 值: about(信息卡), newestPost(最新文章), allInfo(網站信息), newest_comment(最新評論)
      
        # Sticky: Fixed position / noSticky: Not fixed position
        # Sticky: 固定位置 / noSticky: 不固定位置
        home: # on the homepage
          noSticky: "about"
          Sticky: "code,allInfo"
        post: # on the article page
          noSticky: "about"
          Sticky: "newestPost"
        page: # on the page
          noSticky: "about"
          Sticky: "newestPost,allInfo"
        # 菜單欄位置(0: 左 1: 右)
        position: 1 # Sidebar positioning(0: left 1: right)
      
      

      以及在extends下的head引入你的 js 和 css

      示例:

      extends:
        # Insert in head
        # 插入到 head
        head:
        - <link rel="stylesheet" href="/css/customize.css">
        - <script src="/js/custom.js"></script>
      

      最后在首頁就出現效果啦!

      本文由博客一文多發平臺 OpenWrite 發布!

      posted @ 2025-05-29 14:21  konoXIN  閱讀(36)  評論(0)    收藏  舉報
      Sakana Widget右下角定位
      主站蜘蛛池模板: 无线乱码一二三区免费看| 福利一区二区1000| 国产午夜福利精品视频| 亚洲欧美激情在线一区| 秦皇岛市| 亚洲日韩亚洲另类激情文学| 欧美、另类亚洲日本一区二区| 蜜臀精品一区二区三区四区| 方城县| 亚洲国产美国产综合一区| 香蕉EEWW99国产精选免费| 黄色A级国产免费大片视频| 国产中文字幕精品在线| 国产精品亚洲二区亚瑟| 亚洲午夜精品久久久久久抢| 漂亮人妻中文字幕丝袜| 宁蒗| 国产午夜精品理论大片| 四虎影视永久无码精品| 二连浩特市| 欧美黑人乱大交| 亚洲男女羞羞无遮挡久久丫 | 婷婷丁香五月深爱憿情网| 真人无码作爱免费视频| 国产精品一二三区久久狼| 精品国产午夜肉伦伦影院| 亚洲熟妇少妇任你躁在线观看无码| 成人av专区精品无码国产| 国产美女高潮流白浆视频| 毛片无码免费无码播放| 国产国产午夜福利视频| 不卡一区二区三区在线视频| 国产成人精品亚洲日本在线观看| 精品人妻二区中文字幕| 国产自产对白一区| 91久久偷偷做嫩草影院免费看| 精品中文字幕人妻一二| 被灌满精子的少妇视频| 国产三级视频网站| 国产AV影片麻豆精品传媒| 亚洲日韩精品一区二区三区|