├── pages ├── index │ ├── index.json │ ├── index.wxml │ ├── index.wxss │ └── index.js ├── logs │ ├── logs.json │ ├── logs.wxss │ ├── logs.wxml │ └── logs.js └── content │ ├── content.json │ ├── content.wxml │ ├── content.wxss │ └── content.js ├── wechatblog.png ├── sitemap.json ├── app.wxss ├── app.js ├── app.json ├── .gitignore ├── README.md ├── project.config.json ├── utils └── util.js └── LICENSE /pages/index/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "enablePullDownRefresh": true 3 | } -------------------------------------------------------------------------------- /pages/logs/logs.json: -------------------------------------------------------------------------------- 1 | { 2 | "navigationBarTitleText": "查看启动日志" 3 | } -------------------------------------------------------------------------------- /pages/content/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "enablePullDownRefresh": true 3 | } -------------------------------------------------------------------------------- /wechatblog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androiddevelop/WechatBlog/HEAD/wechatblog.png -------------------------------------------------------------------------------- /pages/content/content.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /pages/logs/logs.wxss: -------------------------------------------------------------------------------- 1 | .log-list { 2 | display: flex; 3 | flex-direction: column; 4 | padding: 40rpx; 5 | } 6 | .log-item { 7 | margin: 10rpx; 8 | } 9 | -------------------------------------------------------------------------------- /sitemap.json: -------------------------------------------------------------------------------- 1 | { 2 | "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", 3 | "rules": [{ 4 | "action": "allow", 5 | "page": "*" 6 | }] 7 | } -------------------------------------------------------------------------------- /pages/logs/logs.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | align-items: center; 7 | justify-content: space-between; 8 | padding: 0rpx 16rpx; 9 | box-sizing: border-box; 10 | } 11 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | 3//app.js 2 | App({ 3 | onLaunch: function () { 4 | // 展示本地存储能力 5 | var logs = wx.getStorageSync('logs') || [] 6 | logs.unshift(Date.now()) 7 | wx.setStorageSync('logs', logs) 8 | }, 9 | globalData: { 10 | userInfo: null 11 | } 12 | }) -------------------------------------------------------------------------------- /pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
  • 5 | {{item.title}} 6 |
  • 7 |
    8 |
    -------------------------------------------------------------------------------- /pages/logs/logs.js: -------------------------------------------------------------------------------- 1 | //logs.js 2 | const util = require('../../utils/util.js') 3 | 4 | Page({ 5 | data: { 6 | logs: [] 7 | }, 8 | onLoad: function () { 9 | this.setData({ 10 | logs: (wx.getStorageSync('logs') || []).map(log => { 11 | return util.formatTime(new Date(log)) 12 | }) 13 | }) 14 | } 15 | }) 16 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/index/index", 4 | "pages/logs/logs", 5 | "pages/content/content" 6 | ], 7 | "window": { 8 | "backgroundTextStyle": "dark", 9 | "navigationBarBackgroundColor": "#262626", 10 | "navigationBarTitleText": "小胖轩", 11 | "navigationBarTextStyle": "white" 12 | }, 13 | "sitemapLocation": "sitemap.json" 14 | } -------------------------------------------------------------------------------- /pages/index/index.wxss: -------------------------------------------------------------------------------- 1 | /**index.wxss**/ 2 | 3 | .title { 4 | display: flex; 5 | flex-direction: column; 6 | margin-top: 10px; 7 | margin-bottom: 10px; 8 | background-color: #eee; 9 | border-radius: 5px; 10 | padding: 8px; 11 | font-size: 18px; 12 | } 13 | 14 | .copyright { 15 | font-size: 12px; 16 | color: #888; 17 | padding-bottom: 5px; 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # http directory 22 | https:/ 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | -------------------------------------------------------------------------------- /pages/content/content.wxss: -------------------------------------------------------------------------------- 1 | /* pages/content/content.wxss */ 2 | 3 | .content-container{ 4 | padding-left: 10px; 5 | padding-right: 10px; 6 | display: flex; 7 | font-size: 18px; 8 | padding-top: 8px; 9 | padding-bottom: 8px; 10 | flex-direction: column; 11 | background-color: #ffffff; 12 | } 13 | 14 | .content-img{ 15 | width: auto; 16 | height: auto; 17 | max-width: 100%; 18 | max-height: 100%; 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WechatBlog 2 | **Codeboy博客微信小程序** 3 | 4 | 微信扫码即可查看 5 |
    6 | 7 | 8 | ### 安装调试: 9 | 10 | 1. 请下载[CodeboyBlog](https://github.com/androiddevelop/CodeboyBlog),复制`search`和`wechat`目录到博客根目录,暂时只支持Jekyll博客,不支持`Hexo`博客,其中`search`目录提供博客列表,`wechat`目录提供博客详情。 11 | 12 | 2. 运行`wechat`目录下的 `create.sh` 文件,生成对应的内容模板。 13 | 14 | 3. 部署博客。 15 | 16 | 4. 下载小程序代码,修改部分配置 17 | - /app.json 博客名字(改成自己博客名称)和标题栏样式(非必须)。 18 | - 其他样式请修改wxss。 19 | 20 | 5. 本地测试通过后,发布小程序。 21 | 22 | ### 更新内容: 23 | 24 | #### 2017-11-17 25 | 26 | #### v0.0.2 27 | - 去除博客列表标题中的分类。 28 | 29 | #### v0.0.1 30 | - 添加初版微信小程序支持,可以便捷创建专属于自己博客的小程序。 31 | -------------------------------------------------------------------------------- /project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": false, 5 | "es6": true, 6 | "postcss": true, 7 | "preloadBackgroundData": false, 8 | "minified": true, 9 | "newFeature": true, 10 | "autoAudits": false, 11 | "coverView": true, 12 | "showShadowRootInWxmlPanel": true, 13 | "scopeDataCheck": false, 14 | "useCompilerModule": true 15 | }, 16 | "compileType": "miniprogram", 17 | "libVersion": "1.4.0", 18 | "appid": "wxa7bb69f6e2dc4034", 19 | "projectname": "%E5%B0%8F%E8%83%96%E8%BD%A9", 20 | "simulatorType": "wechat", 21 | "simulatorPluginLibVersion": {}, 22 | "condition": { 23 | "search": { 24 | "current": -1, 25 | "list": [] 26 | }, 27 | "conversation": { 28 | "current": -1, 29 | "list": [] 30 | }, 31 | "miniprogram": { 32 | "current": -1, 33 | "list": [] 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /pages/content/content.js: -------------------------------------------------------------------------------- 1 | // pages/content/content.js 2 | 3 | var url = ''; 4 | 5 | Page({ 6 | 7 | /** 8 | * 页面的初始数据 9 | */ 10 | data: { 11 | 12 | }, 13 | 14 | /** 15 | * 生命周期函数--监听页面加载 16 | */ 17 | onLoad: function (options) { 18 | if(options){ 19 | url = 'https://www.codeboy.me/wechat/content/' + options.path; 20 | wx.setNavigationBarTitle({ 21 | title: options.title 22 | }) 23 | } 24 | var that = this; 25 | wx.showLoading({ 26 | mask: true, 27 | title: '加载中' 28 | }) 29 | wx.request({ 30 | url: url, 31 | success: function (res) { 32 | var content = res.data.replace(/\/img\//g, 'https://www.codeboy.me/img/'); 33 | content = content.replace(//g, '').replace(/<\/pre>/g, ''); 35 | that.setData({ 36 | content: content 37 | }); 38 | wx.hideLoading(); 39 | }, 40 | fail: function (res) { 41 | wx.hideLoading(); 42 | wx.showToast({ 43 | title: '加载失败', 44 | icon: 'failed', 45 | duration: 2000, 46 | mask: true 47 | }); 48 | } 49 | }) 50 | }, 51 | onPullDownRefresh: function () { 52 | this.onLoad(); 53 | wx.stopPullDownRefresh(); 54 | }, 55 | }) -------------------------------------------------------------------------------- /utils/util.js: -------------------------------------------------------------------------------- 1 | const formatTime = date => { 2 | const year = date.getFullYear() 3 | const month = date.getMonth() + 1 4 | const day = date.getDate() 5 | const hour = date.getHours() 6 | const minute = date.getMinutes() 7 | const second = date.getSeconds() 8 | 9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10 | } 11 | 12 | const formatNumber = n => { 13 | n = n.toString() 14 | return n[1] ? n : '0' + n 15 | } 16 | 17 | const stringToBase64 = str =>{ 18 | var c1, c2, c3; 19 | var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 20 | var i = 0, len = str.length, strin = ''; 21 | while (i < len) { 22 | c1 = str.charCodeAt(i++) & 0xff; 23 | if (i == len) { 24 | strin += base64EncodeChars.charAt(c1 >> 2); 25 | strin += base64EncodeChars.charAt((c1 & 0x3) << 4); 26 | strin += "=="; 27 | break; 28 | } 29 | c2 = str.charCodeAt(i++); 30 | if (i == len) { 31 | strin += base64EncodeChars.charAt(c1 >> 2); 32 | strin += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)); 33 | strin += base64EncodeChars.charAt((c2 & 0xF) << 2); 34 | strin += "="; 35 | break; 36 | } 37 | c3 = str.charCodeAt(i++); 38 | strin += base64EncodeChars.charAt(c1 >> 2); 39 | strin += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)); 40 | strin += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)); 41 | strin += base64EncodeChars.charAt(c3 & 0x3F) 42 | } 43 | return strin 44 | } 45 | 46 | module.exports = { 47 | formatTime: formatTime, 48 | stringToBase64: stringToBase64 49 | } -------------------------------------------------------------------------------- /pages/index/index.js: -------------------------------------------------------------------------------- 1 | //index.js 2 | //获取应用实例 3 | const app = getApp() 4 | //请求的url 5 | const request_url = 'https://www.codeboy.me/search/cb-search.json'; 6 | const pageMap ={}; 7 | var tips = '加载中'; 8 | import {stringToBase64} from '../../utils/util.js'; 9 | 10 | Page({ 11 | data: { 12 | blogData: {}, 13 | dataSuccess: false, 14 | loading: true 15 | }, 16 | onLoad: function () { 17 | const that = this; 18 | wx.showLoading({ 19 | mask: true, 20 | title: tips 21 | }) 22 | 23 | tips = '刷新中'; 24 | wx.request({ 25 | url: request_url, //仅为示例,并非真实的接口地址 26 | data: { 27 | }, 28 | header: { 29 | 'content-type': 'application/json' // 默认值 30 | }, 31 | success: function (res) { 32 | if (res.data.code == 0) { 33 | //去除分类标签 34 | for(var i=0;i