1

我使用 pelican 作为静态站点生成器来构建静态站点。我想将它托管在 GitLab Pages 上,并通过 GitLab 与 Makefile 的持续集成让网站生成。

该站点通过其 CI/CD 管道在本地以及 GitLab 上成功构建。构建代码通过上传工件并且作业成功。内容文件在public文件夹中构建和生成。

不知何故,在构建通过并public根据需要将工件上传到文件夹中之后,预计静态站点将托管在 GitLab 页面的用户页面上,例如username.gitlab.io/projectname.

尽管建议的等待时间是 15 分钟到半小时,但即使在 15 多个小时之后,这也不起作用。

还尝试了在自定义子域上托管。子域已验证,但未生成站点。

作为参考,下面提到了正在使用的最少代码。

.gitlab-ci.yml

# default to using the latest Python docker image for builds
image: python:3.7.0

# our build job installs the Python requirements and Pelican
# plugins, then runs ``make publish`` to generate the output
build:
  stage: deploy
  script:
  - apt-get update -qq && apt-get install -y -qq python python-pip
  - python -v
  - pip install  -r requirements.txt
  - git clone --recursive https://github.com/getpelican/pelican-plugins ../plugins
  - pelican -s publishconf.py
  - make publish
# specify the artifacts to save
  artifacts:
    paths:
      - public/
  only:
  - master

发布配置文件

#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import os

AUTHOR = 'Tanya Jain'
SITENAME = 'Tanya Jain'
SITEURL = '/public'
DESCRIPTION = ''
THEME = 'themes/stellarAdventurerTheme'

PATH = 'content'
OUTPUT_PATH = 'public'

鹈鹕配置文件

#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import os

AUTHOR = 'Tanya Jain'
SITENAME = 'Tanya Jain'
SITEURL = '/public'
DESCRIPTION = ''
THEME = 'themes/stellarAdventurerTheme'

PATH = 'content'
OUTPUT_PATH = 'public'

生成文件

PY?=python3
PELICAN?=pelican
PELICANOPTS=

BASEDIR=$(CURDIR)
INPUTDIR=$(BASEDIR)/content
OUTPUTDIR=$(BASEDIR)/public
CONFFILE=$(BASEDIR)/pelicanconf.py
PUBLISHCONF=$(BASEDIR)/publishconf.py

FTP_HOST=localhost
FTP_USER=anonymous
FTP_TARGET_DIR=/

SSH_HOST=localhost
SSH_PORT=22
SSH_USER=root
SSH_TARGET_DIR=/var/www

请帮助您了解如何在 GitLab Pages 上生成网站!

更新1:

尝试了这些也不起作用的更改。然而,我相信这些更改将在 pelican 设置中进行,而不是在 GitLab 的 YAML 中进行。

鹈鹕配置文件

SITEURL = ''

发布配置文件

SITEURL = 'http://subdomain.example.com'
4

2 回答 2

2

非常感谢您的帮助!我已经解决了这个问题。该错误是由于build在 .gitlab-ci.yml 中提到了该工作,并且还缺少该工作pages。使用pages作为工作是部署 GitLab 页面的必要条件,可以在提到的参考资料中进一步阅读。因此,正确的脚本是:

image: python:3.7.0

pages:
    stage: deploy
    script:
    - apt-get update -qq && apt-get install -y -qq python python-pip
    - python -v
    - pip install  -r requirements.txt
    - git clone --recursive https://github.com/getpelican/pelican-plugins ../plugins
    - pelican -s publishconf.py
    - make publish
    artifacts:
        paths:
            - public/
    only:
    - master

参考:

  1. Stackoverflow:GitLab Pages 部署步骤在成功构建后失败
  2. 探索 GitLab 页面(文档)
  3. 为 GitLab 页面创建和调整 GitLab CI/CD
于 2019-08-12T22:29:06.207 回答
2

没有评论和要求澄清的声誉。因此,在答案正文中写下问题/答案。

默认情况下,pelican 使用易于与 python SimpleHTTPServer 一起使用的相对路径。对于 Gitlab 页面,您必须使用绝对 URL。请检查您是否使用了绝对 URL,这可能是问题所在。

# In Publishconf.py
SITEURL = 'https://username.gitlab.io/pelican2048'

参考:#1

来源:使用 Pelican 的静态网站,托管在 Gitlab 上

更新:我相信你已经看到了,但请交叉检查https://gitlab.com/pages/pelicanhttps://mister-gold.pro/posts/en/deploy-pelican-on-gitlab-pages/

希望这可以帮助!

于 2019-08-12T16:54:06.570 回答