tankywoo/simiki

simiki g报错

yi-Xu-0100 opened this issue · 12 comments

错误如下:

simiki g --draft
[INFO]: Start generating markdown files.
[INFO]: Generate 1 pages, include 0 drafts.
[INFO]: Generate catalog page.
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\simiki-script.py", line 11, in <module>
    load_entry_point('simiki==1.6.0.1', 'console_scripts', 'simiki')()
  File "c:\python\python27\lib\site-packages\simiki\cli.py", line 401, in main
    generator.generate(include_draft=args['--draft'])
  File "c:\python\python27\lib\site-packages\simiki\cli.py", line 183, in generate
    self.generate_catalog(self.pages)
  File "c:\python\python27\lib\site-packages\simiki\cli.py", line 235, in generate_catalog
    html = catalog_generator.generate_catalog_html()
  File "c:\python\python27\lib\site-packages\simiki\generators.py", line 403, in generate_catalog_html
    html = self.env.get_template("index.html").render(tpl_vars)
  File "c:\python\python27\lib\site-packages\jinja2\environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "c:\python\python27\lib\site-packages\jinja2\environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "D:\ApplicationDoocument\DocumentForGit\blog\wiki\themes\simple2\index.html", line 1, in top-level template code
    {%- extends "base.html" %}
  File "D:\ApplicationDoocument\DocumentForGit\blog\wiki\themes\simple2\base.html", line 17, in top-level template code
    {% block container %}
  File "D:\ApplicationDoocument\DocumentForGit\blog\wiki\themes\simple2\index.html", line 10, in block "container"
    {{ page.content }}
  File "c:\python\python27\lib\site-packages\jinja2\environment.py", line 397, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'page' is undefined

分别安装python版本为2.7和3.5均不可用,output中仅生成范例文章,技术小白,没有python和git相关基础,只会相关操作命令,google+baidu到现在还是没有解决,希望能够得到解答和帮助。谢谢

你好。

分别安装python版本为2.7和3.5均不可用,output中仅生成范例文章

意思是指『样例』的页面是生成的,但是你额外的文章报错?

请贴出 content 目录下的文件内容,以及 jinja2 的版本号(pip freeze | grep -i jinja2

output目录如下:

-output
  -.git
  -intro
    -gettingstarted.html
  -CNAME

jianja2的版本号为Jinja2==2.7.3

抱歉,看错了

-content
  -intro
   -gettingstarted.md

我主要是奇怪的是,这个开始的时候是没有相关首页样本的吗?而且我的gettingstarted.html在网站上的显示也有问题,地址gettingstarted,是我的config设置有问题吗?
ps:由于昨天莫名github的DNS解析有误,我将这个的线路解析到国外上的,不知道这个会不会有影响。

你好,首先这个域名无法解析。另外页面的生成和解析这块没有关系,先确认本地能否执行 simiki g 生成。

并且你是通过 simiki init 生成一个初始的站点,然后执行 simiki g 无法生成站点吗?你可以在 _config.yml 中加上 debug: True,然后再执行 simiki g 看看输出提示,目前的信息,我还没法判断为何会报 page 未定义。

我查看config文件时,发现在debug的下面有一句index:true,删除之后,simiki g没有问题了,我多次试验没有问题了,结果如下:

simiki g
[DEBUG]: Empty the destination directory
[DEBUG]: Delete file D:\ApplicationDoocument\DocumentForGit\blog\wiki\output\index.html
[DEBUG]: Delete directory D:\ApplicationDoocument\DocumentForGit\blog\wiki\output\intro
[DEBUG]: Delete directory D:\ApplicationDoocument\DocumentForGit\blog\wiki\output\static
[INFO]: Start generating markdown files.
[INFO]: Generate 1 pages, ignore 0 drafts.
[INFO]: Generate catalog page.
[DEBUG]: Installing theme: simple2
[INFO]: Done.

问题出在我没有怎么看懂配置,然后又从网上找一些介绍改的,现在解决了generate的问题,感谢耐心解答。

但是我没有看懂simiki p 这个在哪里预览,我的系统是win10的,使用过hexo搭建过博客,这个预览也是在localhost的某个端口吗?后面需要加参数设置吗?实在是不太了解这些,也不知道该怎么查找这种问题。
我根据simiki的中文文档的部署里的要求,安装了fabricghp-import,config中设置如下,

deploy:
  - type: git
    remote: origin
    branch: gh-pages

但是执行fab deploy结果如下:

fab deploy
[localhost] local: which ghp-import > /dev/null 2>&1; echo $?

Warning: local() encountered an error (return code 1) while executing 'which ghp-import > /dev/null 2>&1; echo $?'

Traceback (most recent call last):
  File "c:\python\python27\lib\site-packages\fabric\main.py", line 756, in main
    *args, **kwargs
  File "c:\python\python27\lib\site-packages\fabric\tasks.py", line 426, in execute
    results['<local-only>'] = task.run(*args, **new_kwargs)
  File "c:\python\python27\lib\site-packages\fabric\tasks.py", line 173, in run
    return self.wrapped(*args, **kwargs)
  File "D:\ApplicationDoocument\DocumentForGit\blog\wiki\fabfile.py", line 145, in deploy
    func(deploy_item)
  File "D:\ApplicationDoocument\DocumentForGit\blog\wiki\fabfile.py", line 71, in deploy_git
    if int(res.strip()):
ValueError: invalid literal for int() with base 10: ''

因为我开始设置的方法可能是手动配置githubpages的那种方法,所以我实验了issue23中lord63提到的方法。

我们可以把 output 加入 gitignore 来忽略每次生成时的变化,master 分支托管源文件(markdown什么的),gh-pages 分支放 output 的静态文件。如果我们使用的是 Project Pages,过程十分简单,你使用 git push -u origin master 把你的源文件 push 上去,而你要更新你的网站的时候,使用 ghp-import -p output 推送你的 output 中的静态文件就行了,它会自动帮你新建分支并推送到 github,第一次和以后每次都是这样。

we need ghp-import to help us do it more efficiently.

Usage: ghp-import [OPTIONS] DIRECTORY
Options:
-n Include a .nojekyll file in the branch.
-m MESG The commit message to use on the target branch.
-p Push the branch to origin/{branch} after committing.
-r REMOTE The name of the remote to push to. [origin]
-b BRANCH Name of the branch to write to. [gh-pages]
-h, --help show this help message and exit

once you have generate your wiki, pushing the static files to github is esay:

$ pip install ghp-import
$ ghp-import -p output

结果显示如下:

git push -u origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 318 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/yi-Xu-0100/wiki.git
   dd99a90..96ff73d  master -> master
Branch master set up to track remote branch master from origin.
 ghp-import -p output
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\ghp-import-script.py", line 11, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 238, in main
    run_import(git, args[0], opts)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 173, in run_import

    start_commit(pipe, git, opts.branch, opts.mesg)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 128, in start_commit
    write(pipe, enc('committer %s <%s> %s\n' % (uname, email, mk_when())))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd6 in position 11: ordinal not in range(128)

而且我的CNAME的设置,或者域名解析设置一直没有弄好,麻烦能给个样例。我购买了域名yixuju.cn,使用hexo搭建了blog在www.yixuju.cn上,希望能将wiki放在wiki.yixuju.cn上,这个DNSPOD那里到底该怎么添加记录,技术小白,全凭兴趣看教程在弄这些,希望能够帮忙普及一下相关知识,网上找的实在没怎么看懂,谢谢。

ps:我现在查看http://wiki.yixuju.cn/intro/gettingstarted
可以显示一个,但主页和其他都不能查看,不知道为什么,我在output目录下使用git push origin gh-pages将刚刚生成的一些css和html上上传到我的github上了,但没有效果,文件地址https://github.com/yi-Xu-0100/wiki/tree/gh-pages

pps:想起来设置root:/wiki,更改为空就好了,然后我重新push了mastergh-pages,页面已经可以正常显示了,感谢啊。

但是这样,难到我只能每次pushmastergh-pages吗,fab deploy的方式还是没有弄懂,望解答,谢谢

  1. index: true 表示使用自定义的首页,这块的报错信息我需要改一下,使其有意义一些。 👍

  2. simiki p 预览的地址默认是 **127.0.0.1:8000`,win 下 logger 有点问题,还没解决,所以相关的提示没有显示 (其实我更建议在 Linux 下使用)

  3. 关于第一个 fab deploy 的结果,建议重新 clone 下来配置,手动配置和 ghp-import 不能混合使用。

  4. 第二个 fab deploy的结果,是混合编码方面问题,在 py27 下, str + unicode 会导致这个问题,你可以修改下 c:\python\python27\lib\site-packages\ghp_import.py 的代码,在128行上面加上:

    print((uname, type(uname)))
    print((email, type(email)))
    print((mk_when(), type(mk_when())))

    我需要确认下这几个字段在你本地显示的结果和类型

  5. 关于 dns 记录,需要根据你目前的 page 类型来确定。大致就是在 dnspod 上针对 wiki.yixuju.cn 做一个 cname 指向 xxx.github.io 这个类型的域名,然后 page 分支下的 CNAME 文件内要写上 wiki.yixuju.cn 这个域名。具体还是建议看官方的文档:https://help.github.com/articles/using-a-custom-domain-with-github-pages/

1,2,3我回头再自己尝试尝试,4的返回结果如下:

 ghp-import -p output
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\ghp-import-script.py", line 11, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python\python27\lib\site-packages\pkg_resources\__init__.py", line 560, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "c:\python\python27\lib\site-packages\pkg_resources\__init__.py", line 2648, in load_entry_point
    return ep.load()
  File "c:\python\python27\lib\site-packages\pkg_resources\__init__.py", line 2302, in load
    return self.resolve()
  File "c:\python\python27\lib\site-packages\pkg_resources\__init__.py", line 2308, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 128
    print((uname, type(uname)))
    ^
IndentationError: unexpected indent

5的话我应该是配置好了。我已经能够打开网站预览了,地址http://wiki.yixuju.cn/,不知道有没有方法让这个上绿锁,github上的设置里好像不行,好像是我解析域名的原因,还有其他的方法吗?

整体我已经完成了这个wiki的构建了,感觉这两天算是不白忙活,今天能得到你的解答着是感谢,网页的样式我感觉很干净,希望这个项目可以越做越好。

  1. 你添加的代码缩进有问题,注意是用 4 个空格,而不是 tab (Python 不允许 tabs 和 spaces 混合)
  2. https (url 栏的绿锁)无法解决,除非你不使用自定义域名,而是使用 xxx.github.io 域名。因为 SSL 证书是和域名绑定的,所以无法给你自定义的域名提供证书,你可以不使用 Github Pages,比如自己买个 VPS,然后在上面部署,过程也会简单很多。 (如果使用Github Pages,且使用 github.io 的域名,则配置方法:https://help.github.com/articles/securing-your-github-pages-site-with-https/)。

结果如下(邮箱地址我就替换成example@github.com了):

ghp-import -p output
(u'example@github.com', <type 'unicode'>)
(u'example@github.com', <type 'unicode'>)
('1491270577 \xd6\xd0\xb9\xfa\xb1\xea\xd7\xbc\xca\xb1\xbc\xe4', <type 'str'>)
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\ghp-import-script.py", line 11, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 241, in main
    run_import(git, args[0], opts)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 176, in run_import

    start_commit(pipe, git, opts.branch, opts.mesg)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 131, in start_commit
    write(pipe, enc('committer %s <%s> %s\n' % (uname, email, mk_when())))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd6 in position 11: ordinal not in range(128)
fatal: Expected committer but didn't get one

fast-import: dumping crash report to .git/fast_import_crash_10884

google了一下这个问题,我尝试在mk-when中添加了与你的代码类似的查看信息,结果如下:

ghp-import -p output
(u'example@github.com', <type 'unicode'>)
(u'example@github.com', <type 'unicode'>)
('\xd6\xd0\xb9\xfa\xb1\xea\xd7\xbc\xca\xb1\xbc\xe4', <type 'str'>)
(1491273804, <type 'int'>)
('\xd6\xd0\xb9\xfa\xb1\xea\xd7\xbc\xca\xb1\xbc\xe4', <type 'str'>)
(1491273804, <type 'int'>)
('1491273804 \xd6\xd0\xb9\xfa\xb1\xea\xd7\xbc\xca\xb1\xbc\xe4', <type 'str'>)
('\xd6\xd0\xb9\xfa\xb1\xea\xd7\xbc\xca\xb1\xbc\xe4', <type 'str'>)
(1491273804, <type 'int'>)
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\ghp-import-script.py", line 11, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 243, in main
    run_import(git, args[0], opts)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 178, in run_import

    start_commit(pipe, git, opts.branch, opts.mesg)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 133, in start_commit
    write(pipe, enc('committer %s <%s> %s\n' % (uname, email, mk_when())))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd6 in position 11: ordinal not in range(128)
fatal: Expected committer but didn't get one
fast-import: dumping crash report to .git/fast_import_crash_16404

函数mk_when的原始内容如下:

def mk_when(timestamp=None):
    if timestamp is None:
        timestamp = int(time.time())
    currtz = time.strftime('%z')
    return "%s %s" % (timestamp,currtz)

我试着修改如下:(在currtz = time.strftime('%z')后面添加.decode('utf-8')

def mk_when(timestamp=None):
    if timestamp is None:
        timestamp = int(time.time())
    currtz = time.strftime('%z').decode('utf-8')
    return "%s %s" % (timestamp,currtz)

得到结果如下:

ghp-import -p output
(u'example@github.com', <type 'unicode'>)
(u'example@github.com', <type 'unicode'>)
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\ghp-import-script.py", line 11, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 241, in main
    run_import(git, args[0], opts)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 176, in run_import

    start_commit(pipe, git, opts.branch, opts.mesg)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 130, in start_commit
    print((mk_when(), type(mk_when())))
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 120, in mk_when
    currtz = time.strftime('%z').decode('utf-8')
  File "c:\python\python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
fatal: Expected committer but didn't get one
fast-import: dumping crash report to .git/fast_import_crash_4936

额,我实在没怎么看懂这块内容,修复不好,修改为'utf-16':

def mk_when(timestamp=None):
    if timestamp is None:
        timestamp = int(time.time())
    currtz = time.strftime('%z').decode('utf-16')
    return "%s %s" % (timestamp,currtz)

显示结果如下:

ghp-import -p output
(u'example@github.com', <type 'unicode'>)
(u'example@github.com', <type 'unicode'>)
(u'1491274558 \ud0d6\ufab9\ueab1\ubcd7\ub1ca\ue4bc', <type 'unicode'>)
fatal: Invalid raw date "1491274558 탖調볗뇊" in ident: xjy123456120@163.com <az
real0100@gmail.com> 1491274558 탖調볗뇊
fast-import: dumping crash report to .git/fast_import_crash_12596
Traceback (most recent call last):
  File "C:\Python\Python27\Scripts\ghp-import-script.py", line 11, in <module>
    load_entry_point('ghp-import==0.5.5', 'console_scripts', 'ghp-import')()
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 241, in main
    run_import(git, args[0], opts)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 176, in run_import

    start_commit(pipe, git, opts.branch, opts.mesg)
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 136, in start_commit
    write(pipe, enc('deleteall\n'))
  File "c:\python\python27\lib\site-packages\ghp_import.py", line 47, in write
    pipe.stdin.write(data)
IOError: [Errno 22] Invalid argument

难道utf-8已经不够了吗……希望我的测试有点帮助。
ps: 不知道coding上能不能搭建,那个好像以强制为https

你给出的输出结果很有帮助,👍 我知道为啥了。

ghp-import 在处理时区这块,默认只考虑 locale 环境变量是 xxx.utf-8 的情况。但是 win 下默认是 gbk 系,所以输出的字符换和 unicode 联结时,无法隐式编码转换。

>> print '\xd6\xd0\xb9\xfa\xb1\xea\xd7\xbc\xca\xb1\xbc\xe4'.decode('gbk')
**标准时间

这块应该根据系统的 locale 来判断时区的解码问题,你可以加上 .decode('gbk') 来临时解决看看。可以给他们报个 bug。

simiki g的问题已经解决,其他问题属于配置问题,感谢回复。