web之git与hugo

Feb 01, 2020 • 4 minutes to read

1. github简介

1.1 目的:托管项目代码

1.2、基本概念

  • 仓库repository
  • 收藏star
  • 复制克隆项目fork:将别人的仓库完整复制过来
  • 发起请求full request
  • 关注watch:关注项目,项目更新可以收到通知
  • 事物卡片issue:发现代码有bug,但是没有成型代码
  • github主页
    • 仓库主页:项目信息,项目代码,版本
    • 个人主页:个人信息

2. git安装和配置

# 注意:以下操作是在ubuntu下进行!
# 1. 安装git
Sudo apt-get install git

# 2. 
git remote -v origin https://github.com/ChuWeiEr/ChuWeiEr.github.io
    
# 3. 设置
git config --global user.name ChuWeiEr
git config --global user.email chuwei178@163.com


# 4. 查看配置情况
git config user.name
git config user.email
# 或者 
git config --list

# 5.SSH设置
# 配置完成后,创建验证用的公钥
ssh-keygen -C 'chuwei178@163.com' -t rsa
# 然后 ls -a查看所有隐藏文件
gedit ~/.ssh/id_rsa.pub
# 打开后复制文件内容,打开github主页,edit profiles ,
# title随便填,内容粘贴刚刚复制的,点击add ssh key,
# 测试ssh key是否成功,使用命令,如果通了证明成功了
ssh -T git@github.com

3. 利用git从本地上传到github

git常用命令 https://www.cnblogs.com/lidabo/p/6845345.html

# 步骤:工作区--暂存区--仓库
# 1、git克隆
# 目的:备份;实现代码共享集中化管理
# 首先用链接将仓库文件clone到本地目录下
git clone 仓库地址
# 2、对仓库进行更改
git init
git add .
git commit -m 'comments'
git status
git pull origin master --allow-unrelated-histories
git push -u origin master

3.1 解释

  • 第一步: 进入所要上传文件的目录输入命令 git init
  • 第二步: 添加到暂存区, git add hello.c
  • 删除文件 git rm -r 文件夹,或者 手动删除后 git add .
  • 第三步:从暂存区添加到仓库, git commit -m ‘add hello.c’(描述)
    • 查看git缓存空间状态指令:git status
  • 第四步:将本地仓库文件传到github仓库:git push -u origin master

3.2 出现的错误及解决方案

# 1. Could not resolve host: github.com
# 方法:ping github.com
# 发现ping不通
sudo vi /etc/hosts
加入192.30.255.112 github.com
成功ping通

# 2.
git pull origin master --allow-unrelated-histories

4. github pages 搭建网站

  • 搭建步骤
  1. 创建个人站点 $ \Rightarrow $ 新建仓库(注:仓库名必须是【用户名.github.io】)
    ps:以下两步如果想要借助hugo、WordPress等创建博客,则不需要操作
  2. 在仓库下新建index.html
    https://chuweier.github.io/
    只能创建静态网页
  3. 将项目变成网页点进项目$ \Rightarrow $ settings $ \Rightarrow $ change theme
    https://github.com/ChuWeiEr/ChuWeiEr.github.io.git

5. windows下git的使用

6. windows下搭建博客

https://blog.51cto.com/u_13933750/3229488

  1. 首先下载hugo

https://github.com/gohugoio/hugo/releases

下载完成后将路径直接添加到系统变量即可

  1. 配置git环境(如上所述)
3. 上传博客步骤

# 下载hugo
wget https://github.com/gohugoio/hugo/releases/download/v0.63.2/hugo_0.63.2_Linux-64bit.deb
dpkg -i hugo_0.63.2_Linux-64bit.deb
# linux下或者
snap install hugo
hugo version


# 配置主题
hugo version
hugo new site blog
cd blog
# 添加主题  https://themes.gohugo.io/ ,放到theme下面
git log #查看上传历史
git remote -v #查看路径
# git@github.com:ChuWeiEr/ChuWeiEr.github.io.git
git remote rm origin
git remote add origin git@github.com:ChuWeiEr/ChuWeiEr.github.io.git
git remote add origin https://github.com/ChuWeiEr/ChuWeiEr.github.io.git
#根目录下,编辑新建的文章,添加内容并保存
hugo new posts/文章名.md
hugo new 任何名字都可以/文章名.md
# 在根目录下
hugo
hugo server --theme notepadium --buildDrafts --watch
# 换到public目录
cd public
git init
git add .
git commit -m 备注
git push -u origin master
# 出现问题
git pull origin master --allow-unrelated-histories

解释

  • 此处直接在jupyter notebook里面写markdown,然后导出为md,导出路径直接到posts里面
  • 构建 Hugo 网站,默认将静态站点保存到 “public” 目录
  • hugo (每次有修改或者上传新文件都要hugo!)
  • 本地预览网站效果
    hugo server --theme=notepadium --buildDrafts --watch
    使用浏览器打开 http://localhost:1313 预览
  • 将网站文件夹转换为git库
  • 生成的 HTML 文件保存在 “public” 目录中
  • public"文件夹会被转换为 Git 库
    cd public
  • 初始化git仓库
    git init
  • 查看public目录下的文件,会发现多了 .git 文件。 ** 注意是在public目录中运行 **
git add .
git commit -m ‘备注'
  • 如果出现问题
    git pull origin master --allow-unrelated-histories
  • 因为之前上传的文件可能有的不在本地
    git push -u origin master

4、配置表情

5、网页

  • 网页在markdown里面要写成如下形式
  • 其实jupyter命令行直接可以实现 😌
.emoji {
font-family: Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols;
}
  1. 无法链接到网站的解决

https://www.cnblogs.com/GyForever1004/p/13702643.html

https://blog.csdn.net/majianfei1023/article/details/107844493

https://blog.csdn.net/qq_34817440/article/details/106420689

最简单的一种办法就是把自动转换功能关掉即可。

输入命令 :

git config core.autocrlf false

(仅对当前git仓库有效)

Webgithugo

编辑器-01-jupyter notebook

生命在于莽撞