Coder Social home page Coder Social logo

Comments (8)

welcome avatar welcome commented on July 20, 2024

Thanks for opening this issue, maintainers will get back to you as soon as possible!

from hexo-theme-next.

issue-label-bot avatar issue-label-bot commented on July 20, 2024

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

from hexo-theme-next.

stevenjoezhang avatar stevenjoezhang commented on July 20, 2024

Or any other method that does not modify the original source code of the theme to achieve it?

Try this

cd ~/your_hexo_root
mkdir scripts
cd scripts
touch name_it_the_way_you_like.js
hexo.extend.filter.register('template_locals', locals => {
  const { theme, page } = locals;
  theme.valine.placeholder = page.placeholder || 'default_value_here';
});

from hexo-theme-next.

aoemon avatar aoemon commented on July 20, 2024

@stevenjoezhang I made the following configuration according to your method:

In hexo/scripts/diff-plh.js :

hexo.extend.filter.register('template_locals', locals => {
    const { theme, page } = locals;
    theme.valine.placeholder = page.placeholder || 'default';
});

And add in the front-matter of a page:

---
placeholder: special
---

But it still shows as 'default'.

I don't know what I did wrong.

from hexo-theme-next.

stevenjoezhang avatar stevenjoezhang commented on July 20, 2024

Sorry I made a mistake that sometimes it's not able to override the theme variable generated by Hexo. I have other suggestions:

  1. In layout/_third-party/comments/valine.njk

NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
NexT.utils.getScript('{{ valine_uri }}', () => {
new Valine(Object.assign({
el : '#valine-comments',
path: location.pathname,
}, {{ theme.valine | json }}
));
}, window.Valine);
});

NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('{{ valine_uri }}', () => {
    new Valine(Object.assign({
      el  : '#valine-comments',
      path: location.pathname,
    }, {{ theme.valine | json }}, {
      placeholder: MY_PLACEHOLDER
    }
    ));
  }, window.Valine);
});

Uncomment custom_file_path.head in NexT config

custom_file_path:
  head: source/_data/head.njk

Create a file named head.njk in source/_data dir of Hexo

<script>
const MY_PLACEHOLDER = {{ page.placeholder | json }} || 'default';
</script>
  1. Or you can fork Valine and build a custom version

from hexo-theme-next.

aoemon avatar aoemon commented on July 20, 2024

@stevenjoezhang This is a good method. Although it still modifies the template file of the theme source code, but still very grateful for your answer.

from hexo-theme-next.

stevenjoezhang avatar stevenjoezhang commented on July 20, 2024

Valine is no longer open source since v1.4 so this may be the most convenient solution at present.

from hexo-theme-next.

github-actions avatar github-actions commented on July 20, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. It is possible issue was solved or at least outdated. Feel free to open new for related bugs.

from hexo-theme-next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.