pages-gem icon indicating copy to clipboard operation
pages-gem copied to clipboard

Gem overrides stylesheet after regenerating site

Open ashmaroli opened this issue 6 years ago • 6 comments

Summary

When github-pages is listed under the group :jekyll_plugins in the Gemfile, then on regeneration, a site has its assets/css/style.css overridden by one bundled with one of the themes in the gem.

This issue came to my notice while investigating jekyll/jekyll#7854.

This issue affects

  • [ ] The site generated by GitHub Pages maybe.. maybe not..
  • [x] Building sites locally

Steps to reproduce

  • Set up a Jekyll site with at least the following:
    • Gemfile
      source 'https://rubygems.org'
      gem 'github-pages', group: :jekyll_plugins
      
    • assets/css/style.css with the following:
      h1 { color: red }
      
    • An index.html that uses the above stylesheet. (either via a layout or directly)
      <!DOCTYPE html>
      <html>
        <head>
          <meta charset="UTF-8"/>
          <title>Test Site</title>
          <link rel="stylesheet" href="/assets/css/style.css" />
        </head>
        <body>
          <h1>Hello World</h1>
        </body>
      </html>
      
  • Serve the site locally and preview at http://localhost:4000/
    bundle exec jekyll serve
    
  • Trigger a regeneration by just adding content to the landing page.
      <h1>Hello World</h1>
    + <p>Lorem ipsum dolor sit amet</p>
    

What did you expect to happen?

Expected the landing page to be rendered with the new content.

What happened instead?

The following would illustrate better:

Before regeneration:

before-regen

After regeneration:

after-regen

ashmaroli avatar Oct 11 '19 07:10 ashmaroli

Workarounds

Disclaimer: Both of the following are undocumented and may have side-effects

  • place the gem outside the jekyll_plugins group in the Gemfile.
    - gem 'github-pages', group: :jekyll_plugins
    + gem 'github-pages'
    
    This would warrant adding all necessary plugins in the config file.
  • Disabling theme in the config file. Setting theme: null in the config file will also prevent the gem from falling back to the primer stylesheet.

ashmaroli avatar Oct 11 '19 07:10 ashmaroli

Hey, fresh installed the gem on MacOS 10.15.4 today. Jekyll was working great until I setup this gem. Exact same behavior happening here, so can confirm this is a thing. Generated assets folder does not contain any of the custom styles, only those from the fallback template. The issue seems to be intermittent, happening only about 25-50% of the time, but very noticeable when making many small changes. Extra detail, I'm using JetBrains IDEs, which I think write to disk on inactivity.

leviem1 avatar Apr 21 '20 12:04 leviem1

I have the same issue. Who can help me?

The _site/index.html built with jekyll build and jekyll serve has not <!DOCTYPE html>, <html>, <head> these tags. Only <h1> <p>.

The _site/index.html built with github-pages works well. It has complete html content.

_config.yml

_config.yml

plugins:
  - jekyll-remote-theme

remote_theme: just-the-docs/just-the-docs

Gemfile

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

group :jekyll_plugins do
  gem "github-pages", "= 228"
  gem "jekyll-remote-theme"
  gem "jekyll-include-cache"
  gem "jekyll-sitemap"
  gem "jekyll-feed"
end

I also tried to put gem "github-pages", "= 228" outside of group :jekyll_plugins. It still has same problem.

Dockerfile

I run building in docker container.

ARG RUBY_VERSION=2.7.4
FROM ruby:$RUBY_VERSION-alpine

WORKDIR /src/site
COPY ./Gemfile /src/site/

RUN apk add --no-cache --virtual .build_deps \
  make build-base && \
  bundle install --verbose && \
  apk del .build_deps

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

ENTRYPOINT ["jekyll"]
CMD ["serve", "-H", "0.0.0.0", "-P", "4000"]
GH_PAGE_IMAGE=my_gh_page
# build gh-page image
docker build -f ./Dockerfile -t ${GH_PAGE_IMAGE} .
# jekyll serve
docker run -it --rm -p 4000:4000 -v "${PWD}:/src/site" ${GH_PAGE_IMAGE}
# jekyll build
docker run -it --rm -v "${PWD}:/src/site" ${GH_PAGE_IMAGE} build

adoyle-h avatar Feb 09 '23 12:02 adoyle-h

@adoyle-h Do you happen to have GitHub pages listed as a plugin in your _config.yml?

leviem1 avatar Feb 09 '23 16:02 leviem1

@adoyle-h Do you happen to have GitHub pages listed as a plugin in your _config.yml?

I tried. But still same issue.

plugins:
  - github-pages
  - jekyll-remote-theme

remote_theme: just-the-docs/just-the-docs

adoyle-h avatar Feb 09 '23 17:02 adoyle-h

@adoyle-h I think I ended up just removing remote theme from my plugins section in _config.yml, so in your example just nuke that whole section.

I also had to make sure to list my remote theme as just-the-docs/just-the-docs@main since it used to default to master, but that may have changed.

leviem1 avatar Feb 09 '23 18:02 leviem1