{"action":"opened","issue":{"url":"https://api.github.com/repos/iuap-design/blog/issues/2","repository_url":"https://api.github.com/repos/iuap-design/blog","labels_url":"https://api.github.com/repos/iuap-design/blog/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/iuap-design/blog/issues/2/comments","events_url":"https://api.github.com/repos/iuap-design/blog/issues/2/events","html_url":"https://github.com/iuap-design/blog/issues/2","id":160560623,"number":2,"title":"windows上jekyll安装指南","user":{"login":"GuoYongfeng","id":8686869,"avatar_url":"https://avatars.githubusercontent.com/u/8686869?v=3","gravatar_id":"","url":"https://api.github.com/users/GuoYongfeng","html_url":"https://github.com/GuoYongfeng","followers_url":"https://api.github.com/users/GuoYongfeng/followers","following_url":"https://api.github.com/users/GuoYongfeng/following{/other_user}","gists_url":"https://api.github.com/users/GuoYongfeng/gists{/gist_id}","starred_url":"https://api.github.com/users/GuoYongfeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GuoYongfeng/subscriptions","organizations_url":"https://api.github.com/users/GuoYongfeng/orgs","repos_url":"https://api.github.com/users/GuoYongfeng/repos","events_url":"https://api.github.com/users/GuoYongfeng/events{/privacy}","received_events_url":"https://api.github.com/users/GuoYongfeng/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-16T01:45:45Z","updated_at":"2016-06-16T01:45:45Z","closed_at":null,"body":"# windows上jekyll安装指南\r\n\r\n## 1. 安装ruby\r\n\r\n到ruby官网或是百度一下，找个包安装即可\r\n\r\n## 2. 安装python2.7版本\r\n\r\n- 下载安装，记得安装的时候几个添加环境变量的选项勾上\r\n- 配置环境变量，这样可以用easy_install命令\r\n\r\n```\r\nC:\\Python27\\Scripts \r\n```\r\n## 3. 安装easy_install\r\n\r\n在D盘新建ez_setup.py文件，以下是文件的代码\r\n\r\n```\r\n#!/usr/bin/env python\r\n\r\n\"\"\"\r\nSetuptools bootstrapping installer.\r\n\r\nMaintained at https://github.com/pypa/setuptools/tree/bootstrap.\r\n\r\nRun this script to install or upgrade setuptools.\r\n\"\"\"\r\n\r\nimport os\r\nimport shutil\r\nimport sys\r\nimport tempfile\r\nimport zipfile\r\nimport optparse\r\nimport subprocess\r\nimport platform\r\nimport textwrap\r\nimport contextlib\r\nimport json\r\nimport codecs\r\n\r\nfrom distutils import log\r\n\r\ntry:\r\n    from urllib.request import urlopen\r\n    from urllib.parse import urljoin\r\nexcept ImportError:\r\n    from urllib2 import urlopen\r\n    from urlparse import urljoin\r\n\r\ntry:\r\n    from site import USER_SITE\r\nexcept ImportError:\r\n    USER_SITE = None\r\n\r\nLATEST = object()\r\nDEFAULT_VERSION = LATEST\r\nDEFAULT_URL = \"https://pypi.io/packages/source/s/setuptools/\"\r\nDEFAULT_SAVE_DIR = os.curdir\r\n\r\n\r\ndef _python_cmd(*args):\r\n    \"\"\"\r\n    Execute a command.\r\n\r\n    Return True if the command succeeded.\r\n    \"\"\"\r\n    args = (sys.executable,) + args\r\n    return subprocess.call(args) == 0\r\n\r\n\r\ndef _install(archive_filename, install_args=()):\r\n    \"\"\"Install Setuptools.\"\"\"\r\n    with archive_context(archive_filename):\r\n        # installing\r\n        log.warn('Installing Setuptools')\r\n        if not _python_cmd('setup.py', 'install', *install_args):\r\n            log.warn('Something went wrong during the installation.')\r\n            log.warn('See the error message above.')\r\n            # exitcode will be 2\r\n            return 2\r\n\r\n\r\ndef _build_egg(egg, archive_filename, to_dir):\r\n    \"\"\"Build Setuptools egg.\"\"\"\r\n    with archive_context(archive_filename):\r\n        # building an egg\r\n        log.warn('Building a Setuptools egg in %s', to_dir)\r\n        _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)\r\n    # returning the result\r\n    log.warn(egg)\r\n    if not os.path.exists(egg):\r\n        raise IOError('Could not build the egg.')\r\n\r\n\r\nclass ContextualZipFile(zipfile.ZipFile):\r\n\r\n    \"\"\"Supplement ZipFile class to support context manager for Python 2.6.\"\"\"\r\n\r\n    def __enter__(self):\r\n        return self\r\n\r\n    def __exit__(self, type, value, traceback):\r\n        self.close()\r\n\r\n    def __new__(cls, *args, **kwargs):\r\n        \"\"\"Construct a ZipFile or ContextualZipFile as appropriate.\"\"\"\r\n        if hasattr(zipfile.ZipFile, '__exit__'):\r\n            return zipfile.ZipFile(*args, **kwargs)\r\n        return super(ContextualZipFile, cls).__new__(cls)\r\n\r\n\r\n@contextlib.contextmanager\r\ndef archive_context(filename):\r\n    \"\"\"\r\n    Unzip filename to a temporary directory, set to the cwd.\r\n\r\n    The unzipped target is cleaned up after.\r\n    \"\"\"\r\n    tmpdir = tempfile.mkdtemp()\r\n    log.warn('Extracting in %s', tmpdir)\r\n    old_wd = os.getcwd()\r\n    try:\r\n        os.chdir(tmpdir)\r\n        with ContextualZipFile(filename) as archive:\r\n            archive.extractall()\r\n\r\n        # going in the directory\r\n        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])\r\n        os.chdir(subdir)\r\n        log.warn('Now working in %s', subdir)\r\n        yield\r\n\r\n    finally:\r\n        os.chdir(old_wd)\r\n        shutil.rmtree(tmpdir)\r\n\r\n\r\ndef _do_download(version, download_base, to_dir, download_delay):\r\n    \"\"\"Download Setuptools.\"\"\"\r\n    egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'\r\n                       % (version, sys.version_info[0], sys.version_info[1]))\r\n    if not os.path.exists(egg):\r\n        archive = download_setuptools(version, download_base,\r\n                                      to_dir, download_delay)\r\n        _build_egg(egg, archive, to_dir)\r\n    sys.path.insert(0, egg)\r\n\r\n    # Remove previously-imported pkg_resources if present (see\r\n    # https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).\r\n    if 'pkg_resources' in sys.modules:\r\n        _unload_pkg_resources()\r\n\r\n    import setuptools\r\n    setuptools.bootstrap_install_from = egg\r\n\r\n\r\ndef use_setuptools(\r\n        version=DEFAULT_VERSION, download_base=DEFAULT_URL,\r\n        to_dir=DEFAULT_SAVE_DIR, download_delay=15):\r\n    \"\"\"\r\n    Ensure that a setuptools version is installed.\r\n\r\n    Return None. Raise SystemExit if the requested version\r\n    or later cannot be installed.\r\n    \"\"\"\r\n    version = _resolve_version(version)\r\n    to_dir = os.path.abspath(to_dir)\r\n\r\n    # prior to importing, capture the module state for\r\n    # representative modules.\r\n    rep_modules = 'pkg_resources', 'setuptools'\r\n    imported = set(sys.modules).intersection(rep_modules)\r\n\r\n    try:\r\n        import pkg_resources\r\n        pkg_resources.require(\"setuptools>=\" + version)\r\n        # a suitable version is already installed\r\n        return\r\n    except ImportError:\r\n        # pkg_resources not available; setuptools is not installed; download\r\n        pass\r\n    except pkg_resources.DistributionNotFound:\r\n        # no version of setuptools was found; allow download\r\n        pass\r\n    except pkg_resources.VersionConflict as VC_err:\r\n        if imported:\r\n            _conflict_bail(VC_err, version)\r\n\r\n        # otherwise, unload pkg_resources to allow the downloaded version to\r\n        #  take precedence.\r\n        del pkg_resources\r\n        _unload_pkg_resources()\r\n\r\n    return _do_download(version, download_base, to_dir, download_delay)\r\n\r\n\r\ndef _conflict_bail(VC_err, version):\r\n    \"\"\"\r\n    Setuptools was imported prior to invocation, so it is\r\n    unsafe to unload it. Bail out.\r\n    \"\"\"\r\n    conflict_tmpl = textwrap.dedent(\"\"\"\r\n        The required version of setuptools (>={version}) is not available,\r\n        and can't be installed while this script is running. Please\r\n        install a more recent version first, using\r\n        'easy_install -U setuptools'.\r\n\r\n        (Currently using {VC_err.args[0]!r})\r\n        \"\"\")\r\n    msg = conflict_tmpl.format(**locals())\r\n    sys.stderr.write(msg)\r\n    sys.exit(2)\r\n\r\n\r\ndef _unload_pkg_resources():\r\n    sys.meta_path = [\r\n        importer\r\n        for importer in sys.meta_path\r\n        if importer.__class__.__module__ != 'pkg_resources.extern'\r\n    ]\r\n    del_modules = [\r\n        name for name in sys.modules\r\n        if name.startswith('pkg_resources')\r\n    ]\r\n    for mod_name in del_modules:\r\n        del sys.modules[mod_name]\r\n\r\n\r\ndef _clean_check(cmd, target):\r\n    \"\"\"\r\n    Run the command to download target.\r\n\r\n    If the command fails, clean up before re-raising the error.\r\n    \"\"\"\r\n    try:\r\n        subprocess.check_call(cmd)\r\n    except subprocess.CalledProcessError:\r\n        if os.access(target, os.F_OK):\r\n            os.unlink(target)\r\n        raise\r\n\r\n\r\ndef download_file_powershell(url, target):\r\n    \"\"\"\r\n    Download the file at url to target using Powershell.\r\n\r\n    Powershell will validate trust.\r\n    Raise an exception if the command cannot complete.\r\n    \"\"\"\r\n    target = os.path.abspath(target)\r\n    ps_cmd = (\r\n        \"[System.Net.WebRequest]::DefaultWebProxy.Credentials = \"\r\n        \"[System.Net.CredentialCache]::DefaultCredentials; \"\r\n        '(new-object System.Net.WebClient).DownloadFile(\"%(url)s\", \"%(target)s\")'\r\n        % locals()\r\n    )\r\n    cmd = [\r\n        'powershell',\r\n        '-Command',\r\n        ps_cmd,\r\n    ]\r\n    _clean_check(cmd, target)\r\n\r\n\r\ndef has_powershell():\r\n    \"\"\"Determine if Powershell is available.\"\"\"\r\n    if platform.system() != 'Windows':\r\n        return False\r\n    cmd = ['powershell', '-Command', 'echo test']\r\n    with open(os.path.devnull, 'wb') as devnull:\r\n        try:\r\n            subprocess.check_call(cmd, stdout=devnull, stderr=devnull)\r\n        except Exception:\r\n            return False\r\n    return True\r\ndownload_file_powershell.viable = has_powershell\r\n\r\n\r\ndef download_file_curl(url, target):\r\n    cmd = ['curl', url, '--location', '--silent', '--output', target]\r\n    _clean_check(cmd, target)\r\n\r\n\r\ndef has_curl():\r\n    cmd = ['curl', '--version']\r\n    with open(os.path.devnull, 'wb') as devnull:\r\n        try:\r\n            subprocess.check_call(cmd, stdout=devnull, stderr=devnull)\r\n        except Exception:\r\n            return False\r\n    return True\r\ndownload_file_curl.viable = has_curl\r\n\r\n\r\ndef download_file_wget(url, target):\r\n    cmd = ['wget', url, '--quiet', '--output-document', target]\r\n    _clean_check(cmd, target)\r\n\r\n\r\ndef has_wget():\r\n    cmd = ['wget', '--version']\r\n    with open(os.path.devnull, 'wb') as devnull:\r\n        try:\r\n            subprocess.check_call(cmd, stdout=devnull, stderr=devnull)\r\n        except Exception:\r\n            return False\r\n    return True\r\ndownload_file_wget.viable = has_wget\r\n\r\n\r\ndef download_file_insecure(url, target):\r\n    \"\"\"Use Python to download the file, without connection authentication.\"\"\"\r\n    src = urlopen(url)\r\n    try:\r\n        # Read all the data in one block.\r\n        data = src.read()\r\n    finally:\r\n        src.close()\r\n\r\n    # Write all the data in one block to avoid creating a partial file.\r\n    with open(target, \"wb\") as dst:\r\n        dst.write(data)\r\ndownload_file_insecure.viable = lambda: True\r\n\r\n\r\ndef get_best_downloader():\r\n    downloaders = (\r\n        download_file_powershell,\r\n        download_file_curl,\r\n        download_file_wget,\r\n        download_file_insecure,\r\n    )\r\n    viable_downloaders = (dl for dl in downloaders if dl.viable())\r\n    return next(viable_downloaders, None)\r\n\r\n\r\ndef download_setuptools(\r\n        version=DEFAULT_VERSION, download_base=DEFAULT_URL,\r\n        to_dir=DEFAULT_SAVE_DIR, delay=15,\r\n        downloader_factory=get_best_downloader):\r\n    \"\"\"\r\n    Download setuptools from a specified location and return its filename.\r\n\r\n    `version` should be a valid setuptools version number that is available\r\n    as an sdist for download under the `download_base` URL (which should end\r\n    with a '/'). `to_dir` is the directory where the egg will be downloaded.\r\n    `delay` is the number of seconds to pause before an actual download\r\n    attempt.\r\n\r\n    ``downloader_factory`` should be a function taking no arguments and\r\n    returning a function for downloading a URL to a target.\r\n    \"\"\"\r\n    version = _resolve_version(version)\r\n    # making sure we use the absolute path\r\n    to_dir = os.path.abspath(to_dir)\r\n    zip_name = \"setuptools-%s.zip\" % version\r\n    url = download_base + zip_name\r\n    saveto = os.path.join(to_dir, zip_name)\r\n    if not os.path.exists(saveto):  # Avoid repeated downloads\r\n        log.warn(\"Downloading %s\", url)\r\n        downloader = downloader_factory()\r\n        downloader(url, saveto)\r\n    return os.path.realpath(saveto)\r\n\r\n\r\ndef _resolve_version(version):\r\n    \"\"\"\r\n    Resolve LATEST version\r\n    \"\"\"\r\n    if version is not LATEST:\r\n        return version\r\n\r\n    meta_url = urljoin(DEFAULT_URL, '/pypi/setuptools/json')\r\n    resp = urlopen(meta_url)\r\n    with contextlib.closing(resp):\r\n        try:\r\n            charset = resp.info().get_content_charset()\r\n        except Exception:\r\n            # Python 2 compat; assume UTF-8\r\n            charset = 'UTF-8'\r\n        reader = codecs.getreader(charset)\r\n        doc = json.load(reader(resp))\r\n\r\n    return str(doc['info']['version'])\r\n\r\n\r\ndef _build_install_args(options):\r\n    \"\"\"\r\n    Build the arguments to 'python setup.py install' on the setuptools package.\r\n\r\n    Returns list of command line arguments.\r\n    \"\"\"\r\n    return ['--user'] if options.user_install else []\r\n\r\n\r\ndef _parse_args():\r\n    \"\"\"Parse the command line for options.\"\"\"\r\n    parser = optparse.OptionParser()\r\n    parser.add_option(\r\n        '--user', dest='user_install', action='store_true', default=False,\r\n        help='install in user site package')\r\n    parser.add_option(\r\n        '--download-base', dest='download_base', metavar=\"URL\",\r\n        default=DEFAULT_URL,\r\n        help='alternative URL from where to download the setuptools package')\r\n    parser.add_option(\r\n        '--insecure', dest='downloader_factory', action='store_const',\r\n        const=lambda: download_file_insecure, default=get_best_downloader,\r\n        help='Use internal, non-validating downloader'\r\n    )\r\n    parser.add_option(\r\n        '--version', help=\"Specify which version to download\",\r\n        default=DEFAULT_VERSION,\r\n    )\r\n    parser.add_option(\r\n        '--to-dir',\r\n        help=\"Directory to save (and re-use) package\",\r\n        default=DEFAULT_SAVE_DIR,\r\n    )\r\n    options, args = parser.parse_args()\r\n    # positional arguments are ignored\r\n    return options\r\n\r\n\r\ndef _download_args(options):\r\n    \"\"\"Return args for download_setuptools function from cmdline args.\"\"\"\r\n    return dict(\r\n        version=options.version,\r\n        download_base=options.download_base,\r\n        downloader_factory=options.downloader_factory,\r\n        to_dir=options.to_dir,\r\n    )\r\n\r\n\r\ndef main():\r\n    \"\"\"Install or upgrade setuptools and EasyInstall.\"\"\"\r\n    options = _parse_args()\r\n    archive = download_setuptools(**_download_args(options))\r\n    return _install(archive, _build_install_args(options))\r\n\r\nif __name__ == '__main__':\r\n    sys.exit(main())\r\n```\r\n\r\n然后安装\r\n\r\n```\r\n$ cd /d/\r\n$ python ez_setup.py\r\n```\r\n\r\n这个时候，可能会有报语法错什么的，和python版本有关，建议下载2.x系列版本的python\r\n\r\n## 4. 安装jekyll\r\n\r\n安装\r\n\r\n```\r\n$ gem install jekyll\r\n```\r\n\r\n但是由于下载镜像源的问题，会报错\r\n\r\n```\r\nERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)\r\n    Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/jekyll-3.1.6.gemspec.rz)\r\n\r\n```\r\n\r\n需要改变镜像，可以指到淘宝的镜像\r\n\r\n```\r\n$ gem sources --remove https://rubygems.org/\r\n$ gem sources -a https://ruby.taobao.org/\r\n```\r\n\r\n如果不行，换这个\r\n\r\n```\r\n$ gem source -l http://rubygems.org/\r\n$ gem source -a http://production.cf.rubygems.org\r\n```\r\n\r\n然后执行\r\n\r\n```\r\n$ gem install jekyll\r\nSuccessfully installed colorator-0.1\r\nSuccessfully installed sass-3.4.22\r\nSuccessfully installed jekyll-sass-converter-1.4.0\r\nSuccessfully installed rb-fsevent-0.9.7\r\nSuccessfully installed ffi-1.9.10-x86-mingw32\r\nSuccessfully installed rb-inotify-0.9.7\r\nSuccessfully installed listen-3.0.8\r\nSuccessfully installed jekyll-watch-1.4.0\r\n```\r\n\r\n这样安装jekyll成功了\r\n\r\n```\r\n$ jekyll -v\r\njekyll 3.1.6\r\n```\r\n"}}
{"actor":{"display_login":"GuoYongfeng"}}