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

{docsify-updated} cannot show as expected in GitHub pages #1157

Closed
baicaihenxiao opened this issue May 5, 2020 · 13 comments
Closed

{docsify-updated} cannot show as expected in GitHub pages #1157

baicaihenxiao opened this issue May 5, 2020 · 13 comments
Labels
build This is related to build process needs discussion

Comments

@baicaihenxiao
Copy link

Bug Report

Steps to reproduce

I add this script to index.html so that {docsify-updated} can be shown at the bottom of every pags.

hook.beforeEach(function(content) {
  return content + '\n\n----\n\n' + '<p style="color: inherit; font-weight: normal; text-decoration: none; color: #828282;">Last updated <b>{docsify-updated}</b></p>';
});

What is current behaviour

It works well at my local computer, that is, the file updated at 04.22.2020 will show 04.22.2020, the file updated at 05.04 will show 05.04. However, when I made another commit while not modify these two files at 05.05.2020,and push the new commit to GitHub, all pages depolyed in GitHub pages show 05.05.2020 at bottom. Local docsify pages still work well and show 04.22 and 05.04.

What is the expected behaviour

{docsify-updated} shows the same behaviour at both the local and github pages environment


Maybe this problem is not created by docsify, because it works at my local computer. Is it true that github modify all the files even my new commit only contains one single file?

@sy-records
Copy link
Member

sy-records commented May 6, 2020

Please create a reproducible sandbox

Edit 307qqv236

Or github repo address...

@jingqinglin
Copy link

Please create a reproducible sandbox

Edit 307qqv236

Or github repo address...

Hi, I have the same problem and I create a repo on gitee.

Repo address: https://gitee.com/JingqingLin/docsify-test
Gitee Pages address: https://jingqinglin.gitee.io/docsify-test

The first page was updated on 2020/06/02 20:42 and the second page was updated on 2020/06/02 20:45, but all pages was show 2020/06/02 20:45.

@sy-records
Copy link
Member

Can you try to run on a server without a CDN? I think this is still a caching problem. @jingqinglin

@jingqinglin
Copy link

Can you try to run on a server without a CDN? I think this is still a caching problem. @jingqinglin

I put it on VPS, and the time is right.

If I deploy it on GitHub Pages, does {docsify-updated} show file modification time or show commit time?

@sy-records
Copy link
Member

@jingqinglin You can try it use github pages.

gitee:
image

vps:

image

@jingqinglin
Copy link

jingqinglin commented Jun 3, 2020

I put it on GitHub Pages, {docsify-updated} shows commit time. But all files also show the same time. Is there any way to solve this problem?

@sy-records
Copy link
Member

There doesn't seem to be a good solution. 😅
Get the last-modified value, but both the github page and the gitee page are cached release times, so they are consistent.
@anikethsaha Do you have any ideas?

@sy-records sy-records added build This is related to build process Need discussion labels Jun 3, 2020
@anikethsaha
Copy link
Member

I forgot the context of this issue. I will check this soon.

@yzhang-gh
Copy link

yzhang-gh commented Sep 2, 2020

I did a little search and found this, Last Modified Dates for GitHub Pages Jekyll Posts.

Basically, it uses GitHub API https://api.github.com/repos/{owner}/{repo}/commits?path={path} to get the metadata. I have checked and it does work as described (just type the url in the browser and you get a JSON array).

Now the problem is how to extract path from the parameter url here.

updatedAt: xhr.getResponseHeader('last-modified'),

For me it is simply taking the string after yzhang-gh/{repo}/ path is simply your docs root + url. But I'm not sure whether we need to deal with other cases like custom domain.

@ghost
Copy link

ghost commented Sep 13, 2020

Same problem. Any progress?

@ghost
Copy link

ghost commented Aug 1, 2021

I have the same problem.
Every time I push new commits to github. {docsify-updated} in all pages is changed to the time of the latest push time.

but localhost the time is ok.

@sy-records
Copy link
Member

Thank you @yzhang-gh for your comment #1157 (comment)

I provide some code for interested users to create a plugin.

Take docsify's repository as an example

  window.$docsify = {
    plugins: [
      function (hook, vm) {
        hook.beforeEach(function (html) {
          date_url = 'https://api.github.com/repos/docsifyjs/docsify/commits?per_page=1&path=' + vm.config.basePath + vm.route.file;
          fetch(date_url)
            .then((response) => {
              return response.json();
            })
            .then((commits) => {
              var modified = commits[0]['commit']['committer']['date'].slice(0, 10);
              document.getElementById('last-modified').textContent = "Last Modified: " + modified;
            });
          return (
            html +
            '\n\n----\n\n' +
            '<span id="last-modified"></span>'
          );
        });
      }
    ]
  };

image

jingqinglin pushed a commit to jingqinglin/blog that referenced this issue Aug 1, 2021
@rxmapple
Copy link

rxmapple commented Aug 3, 2021

HI ,this is a demo plugin:
https://github.com/rxmapple/docsify-last-modified

@sy-records sy-records closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build This is related to build process needs discussion
Projects
None yet
Development

No branches or pull requests

7 participants