GitHub contents

GitHub PagesからあらゆるGitHub関係の記述をお引越し。

迷子なURL対策

かなり前というか、1995年から作っていたサイトに、今でもLinux系のリンク経由で飛んできていたのにびっくり。
ありがとう、Check your website’s backlinks -SEO Toolbox
なので、GitHubからリダイレクトするように設定してみた。

_layouts/redirected.htmlに、こういうファイルを作成。

Gemfileにも追加。

group :jekyll_plugins do
	gem 'jekyll-redirect-from'
end

_config.ymlに追加。

plugins:
  - jekyll-redirect-from

リダイレクトしたいURLのある場所に、ファイルを設置。
例としてあげたのは、実際に最近も廻ってきているらしい、Linux関係の設定。
どこにも書いてなかったが、フォルダは/_Linux/ではなく、アンダーバー無しの/Linux/に置くべし。
嘘ですごめんなさい、フォルダは自由です。permalinkさえちゃんと設定されていれば、どこに置いても問題無しです。
自分の場合はredirectedフォルダに放り込んであります。

---
layout: redirected
sitemap: false
permalink: /Linux/
redirect_to: https://1995.treetop.to/Linux/
---

あとは通常通りにbundle updateやらjekyll sやらでできた。
お試しで/Linux/indexにアクセスすると、スパーンっとリダイレクトされるように。

手元のファイル群を管理したい

GitHub Pagesから離れているので、あとで別の場所に置き直すかも。

  1. 管理したいファイル群が入っているフォルダに移動して、git用に初期化
    $ git init
    
  2. さっそく中身を見てみると、こんな感じで戻ってきた1
    $ git status
    On branch master
    No commits yet
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    ...
    nothing added to commit but untracked files present (use "git add" to track)
    
  3. 全部放り込む
    $ git add -A
    
  4. そして、コメントを付けてcommit
    $ git commit -m "new repository from existing files"
    [master (root-commit) 16cfb94] new repository from existing files
     nn files changed, nnn insertions(+)
    ...
    
  5. こう?
    $ eval `ssh-agent`
    Agent pid nnnn
    
  6. でもって?
    $ ssh-add ~/.ssh/id_rsa
    Identity added: /c/Users/<user>/.ssh/id_rsa (/c/Users/<user>/.ssh/id_rsa)
    
  7. GitHub上で空のリポジトリを作成(上記「リポジトリを作成」参照)
  8. 追加
    $ git remote add origin https://github.com/<user>/<repogitory>.git
    
    • もしfatal: remote origin already exists.というエラーが出たら、こんな状態になっているかと
        $ cat .git/config
        [core]
       repositoryformatversion = 0
       filemode = false
       bare = false
       logallrefupdates = true
       symlinks = false
       ignorecase = true
        [remote "origin"]
       url = https://github.com/<username>/<repository>.git
       fetch = +refs/heads/*:refs/remotes/origin/*
      
    • 下記コマンドを実行
        $ git remote rm origin
      
    • 確認
        $ cat .git/config
        [core]
       repositoryformatversion = 0
       filemode = false
       bare = false
       logallrefupdates = true
       symlinks = false
       ignorecase = true
      
    • その状態でgit remote add ...を実行
  9. そして放流(?)
    $ git push -u origin master
    Counting objects: 19, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (16/16), done.
    Writing objects: 100% (19/19), 524.54 KiB | 22.81 MiB/s, done.
    Total 19 (delta 0), reused 0 (delta 0)
    To https://github.com/<username>/<repository>.git
     * [new branch]      master -> master
    Branch 'master' set up to track remote branch 'master' from 'origin'.
    

noindex, nofollow

各記事のFront Matterか、または_config.ymlの記事生成設定に追加

robots: "noindex, nofollow"

_includes/head.htmlに追加

{% if page.robots %}
<meta name="robots" content="{{page.robots}}" />
{% endif %}

これだけで、生成したらタグが追加されるように。

<meta name="robots" content="noindex, nofollow" />

robotsに限らず、metaタグを増やせそうな。

  1. インデントがおかしくなるので、空白行は削除してます。