Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override theme's `scheme` from main config [solved] #44

Closed
sully90h opened this issue Jan 17, 2018 · 14 comments

Comments

@sully90h
Copy link
Contributor

commented Jan 17, 2018

I agree and want to create new issue


Expected behavior

The theme's scheme is correctly set from the main _config.yml file, using the theme_config setting explained here: hexojs/hexo#757

Actual behavior

All tested configuration settings can be set from a site's primary _config.yml file, except for scheme.

Steps to reproduce the behavior

Here is a short script that reproduces the behavior:

#!/bin/sh

# Initialize a hexo project with `hexo-cli`.
hexo init mytest
cd mytest
npm install

# Install the NeXT theme
git clone https://github.com/theme-next/hexo-theme-next themes/next
sed -i 's/theme: landscape/theme: next/g' _config.yml

# Configure the theme from the main config file, using `theme_config`
printf "
theme_config:
  scheme: Pisces
  menu:
    set from main: / || home

" >> _config.yml

# Serve the site on localhost:4000
hexo serve

When viewing the site, the theme's menu was properly overridden, but the theme's scheme was not.

  • Link(s) to source code or any useful link(s):

Node.js and NPM Information

node -v && npm -v
v8.4.0
5.6.0

Package dependencies Information

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.4.4"
  },
  "dependencies": {
    "hexo": "^3.2.0",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-stylus": "^0.3.1",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-server": "^0.2.0"
  }
}

Hexo Information

Hexo version

exo -v
hexo: 3.4.4
hexo-cli: 1.0.4
os: Linux 4.9.0-3-amd64 linux x64
http_parser: 2.7.0
node: 8.4.0
v8: 6.0.286.52
uv: 1.13.1
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 57
nghttp2: 1.22.0
openssl: 1.0.2l
icu: 59.1
unicode: 9.0
cldr: 31.0.1
tz: 2017b

Hexo Configuration

Default, except for theme_config at the end.

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html           
## Source: https://github.com/hexojs/hexo/                    
                                                              
# Site               
title: Hexo             
subtitle:               
description:     
author: John Doe
language:       
timezone:                      
                                                 
# URL               
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com                            
root: /                                         
permalink: :year/:month/:day/:title/              
permalink_defaults:                             
                       
# Directory          
source_dir: source
public_dir: public
tag_dir: tags                             
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang    
skip_render:                                               
                                                              
# Writing                                                     
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type:

theme_config:
  scheme: Pisces
  menu:
    set from main: / || home

NexT Information

NexT Version:

  • Latest Master branch.
  • Latest Release version.
  • Old version

NexT Scheme:

  • All schemes
  • Muse
  • Mist
  • Pisces
  • Gemini

NexT Configuration:

Default. No modifications: https://github.com/theme-next/hexo-theme-next/blob/7ee28e7d65681f06e509735697573ab857010b11/_config.yml

Other Information

hexothemeschemeconfig

@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

# ---------------------------------------------------------------
# Theme Core Configuration Settings
# ---------------------------------------------------------------

# Set to true, if you want to fully override the default configuration.
# Useful if you don't want to inherit the theme _config.yml configurations.
override: false
theme_config:
+ override: true
  scheme: Pisces
  menu:
    set from main: / || home

In this case u need to copy all NexT settings from NexT config to Hexo config.


Or u can use data-files.

@ivan-nginx ivan-nginx added the Backlog label Jan 17, 2018
@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

@HuntedCodes if scheme: Muse option will be commented in default NexT config, all works fine?

@sully90h

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

@ivan-nginx I just tried commenting out all schemes in themes/next/_config.yml.

Even with override: true, and all theme settings copied to the main _config.yml, Hexo still uses Muse.

Here are updated reproduction steps that I followed:

#!/bin/sh

# Initialize a hexo project with `hexo-cli`.
hexo init mytest
cd mytest
npm install

# Install the NeXT theme
git clone https://github.com/theme-next/hexo-theme-next themes/next
sed -i 's/theme: landscape/theme: next/g' _config.yml

# Append the entire NeXT config to main config, under 'theme_config:`
printf "\ntheme_config:\n" >> _config.yml
cat themes/next/_config.yml | sed 's/^/  /g' >> _config.yml

# Enable full theme override
sed -i 's/override: false/override: true/g' _config.yml

# Change scheme from "Muse" to "Pisces". Site should show Pisces scheme.
sed -i 's/scheme: Muse/#scheme: Muse/g' _config.yml
sed -i 's/#scheme: Pisces/scheme: Pisces/g' _config.yml

# Comment out the default scheme in the theme.
sed -i 's/scheme: Muse/#scheme: Muse/g' themes/next/_config.yml

# Change theme menu item to show theme_config is working correctly
sed -i 's/home:/XXXXXXX:/g' _config.yml

# Serve the site on localhost:4000
hexo serve

Thanks for pointing out Data Files. I hadn't seen those before.

@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

I also found this issue — theme config overwrite root config.
So, Hexo first read scheme: Pisces from root config and after that Hexo read default scheme: Muse from NexT config and override by it.

@sully90h

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

That issue references the pull request that implemented theme_config (hexojs/hexo#757). There is also PR to have it documented (hexojs/site#634).

@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

Ok, but u comment #scheme: Muse option in default Next config, right?
So, we must get on out:

# ---------------------------------------------------------------
# Scheme Settings
# ---------------------------------------------------------------

# Schemes
#scheme: Muse
#scheme: Mist
#scheme: Pisces
#scheme: Gemini

And we add in Hexo config this:

theme_config:
  scheme: Pisces

And still load Muse scheme with this settings? This override by commented #scheme: Pisces or what? A little bit strange.
Try to clear all commented schemes in default NexT config, still Muse loaded?

@sully90h

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

Sure did, still loads Muse:

  • All schemes were commented out in themes/next/_config.yml.
  • All configuration settings were copied from themes/next/_config.yml to _config.yml, under theme_config.
  • Pisces was enabled in _config.yml.
  • Set override: true in both themes/next/_config.yml and _config.yml.

Main config file:

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

.......

theme_config:
  # ---------------------------------------------------------------
  # Theme Core Configuration Settings
  # ---------------------------------------------------------------
  
  # Set to true, if you want to fully override the default configuration.
  # Useful if you don't want to inherit the theme _config.yml configurations.
  override: true
  
.......

  menu:
    XXXXXXX: / || home

.......
  
  # ---------------------------------------------------------------
  # Scheme Settings
  # ---------------------------------------------------------------
  
  # Schemes
  #scheme: Muse
  #scheme: Mist
  scheme: Pisces
  #scheme: Gemini
  
.......

NeXT config file:

# ---------------------------------------------------------------
# Theme Core Configuration Settings
# ---------------------------------------------------------------

# Set to true, if you want to fully override the default configuration.
# Useful if you don't want to inherit the theme _config.yml configurations.
override: true

.......

# ---------------------------------------------------------------
# Scheme Settings
# ---------------------------------------------------------------

# Schemes
#scheme: Muse
#scheme: Mist
#scheme: Pisces
#scheme: Gemini

.......
@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

Please, try to reproduce steps above.

@sully90h

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

I updated my comment above, to remove the extra settings. It shows the config files, from after the steps were reproduced, that generate Muse instead of Pisces.

The above script automatically reproduces the steps.

@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

  1. Don't need to touch override option anymore.
  2. When u see generated Muse theme, in the footer u see «Theme — NexT.Muse v6.0.1» or «Theme — NexT.Pisces v6.0.1»? Because i trying to change on Gemini and see Gemini in footer, but current visual scheme is still Muse. Can u confirm it?
@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

Alright, find it. Need some time for fix, wait..

@ivan-nginx ivan-nginx added the Bug label Jan 17, 2018
@sully90h

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

Confirmed. Even though the style shows Muse, the footer says:

Theme — NexT.Pisces v6.0.1

@ivan-nginx

This comment has been minimized.

Copy link
Member

commented Jan 18, 2018

@HuntedCodes ok, fixed in 1b0b53a

Detailed full instructions already updated in data-files docs and for now u can use any options from NexT with theme_config + 2 spaces indent in main Hexo config (as u used above, without override option (it's now only for data-files)) — all added options will be rewrited.


The trouble was in hexo-renderer-stylus which by default get all settings from theme's config, not from main Hexo config, without any fallback.


If issue solved, close it please.

@ivan-nginx ivan-nginx added this to the v6.0.2 milestone Jan 18, 2018
@ivan-nginx ivan-nginx added Solved and removed Backlog labels Jan 18, 2018
@ivan-nginx ivan-nginx changed the title Override theme's `scheme` from main config Override theme's `scheme` from main config [fix added] Jan 18, 2018
ivan-nginx added a commit that referenced this issue Jan 18, 2018
@sully90h

This comment has been minimized.

Copy link
Contributor Author

commented Jan 18, 2018

The fix works. Thanks for the quick remediation!

Configuration is so much simpler now, without override or touching the theme's config file:

  1. Initialize a Hexo project
  2. Install the NeXT theme
  3. Add theme_config with scheme: Pisces
  4. Serve the site
#!/bin/sh

# Initialize a hexo project with `hexo-cli`.
hexo init mytest
cd mytest
npm install

# Install the NeXT theme
git clone https://github.com/theme-next/hexo-theme-next themes/next
sed -i 's/theme: landscape/theme: next/g' _config.yml

# Configure NeXT scheme in main config
printf "\ntheme_config:\n  scheme: Pisces" >> _config.yml

# Serve the site on localhost:4000
hexo serve
@sully90h sully90h closed this Jan 18, 2018
@ivan-nginx ivan-nginx changed the title Override theme's `scheme` from main config [fix added] Override theme's `scheme` from main config [solved] Mar 4, 2019
@theme-next theme-next locked as resolved and limited conversation to collaborators Apr 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants
You can’t perform that action at this time.