question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get lastUpdated date of page?

See original GitHub issue

Bug Report

I am trying to display the lastupdate time on each page. However, the lastupdated time o all pages is the same, even though I just updated one of them.

Steps to reproduce

I am using this to get the time:

...
hook.beforeEach(function(html) {
  return addLastUpdatedPlaceholder(html);
});

hook.afterEach(function(html, next) {
  const plugins = [insertLastUpdated];
  const finalHtml = plugins.reduce((accHtml, plugin) => plugin(accHtml), html);
  next(finalHtml);
});
...

function addLastUpdatedPlaceholder(html) {
    var footer = [
        '\n<footer class="last-updated">',
        `<small>__lastupdated__</small>`,
        '</footer>'
    ].join('');
    return html + footer;
}

function insertLastUpdated(html) {
    return html.replace(/__lastupdated__/, `Page last updated: ${window.$docsify.lastUpdated}`);
}

What is current behaviour

Displaying same time on all pages.

What is the expected behaviour

Display time of when page was last updated.

Other relevant information

  • [ x] Bug does still occur when all/other plugins are disabled?

  • Your OS: OSX

  • Node.js version: 10.15.3

  • npm/yarn version: 6.4.1

  • Browser version: Chrome 83

  • Docsify version: 4.4.0

  • Docsify plugins: Custom

Please create a reproducible sandbox

Edit 307qqv236

Mention the docsify version in which this bug was not present (if any)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sy-recordscommented, Jul 31, 2020

you can use {docsify-updated}

for example :

window.$docsify = {
  plugins: [
    function(hook, vm) {
      hook.beforeEach(function(html) {
        return (
          html +
          '\n----\n' +
          'Last modified {docsify-updated} ' 
        );
      });
    }
  ]
};

However, if you deploy using a github page, you usually get the same time.

1reaction
joetideecommented, Jul 3, 2020

I think this did it:

...
hook.beforeEach(function(html) {
          return addLastUpdatedPlaceholder(html, '{docsify-updated}');
      });
...
function addLastUpdatedPlaceholder(html, lastUpdated) {
    var footer = [
        '\n<footer class="last-updated">',
        `<small>Page last updated: ${lastUpdated}</small>`,
        '</footer>'
    ].join('');
    return html + footer;
}

As per, https://github.com/docsifyjs/docsify/blob/314e2d9d39a024270403a42eb19bd98e6cce8d17/docs/write-a-plugin.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

9 Ways to Check Webpage Last Updated Time [Step-by-Step]
Open the webpage. Look for the content metadata next to the page title or at the beginning/end of the webpage. Find a date...
Read more >
How to find out when a website was last ... - The Windows Club
Open the website that you need to check. Hit the F12 key on your keyboard. ... An alert will be invoked on the...
Read more >
How to Find the Most Recently Updated Date of a Web Page
To find the last updated date, simply use a free Google cache checking tool. Or, find the cached data in your Google Search....
Read more >
How To Check When a Website Was Last Updated? - Siteefy
4 Simple Checks To See When a Website Was Last Updated · 1. View the Source Code · 2. Check the XML Sitemap...
Read more >
Determine Last Modified Date of a Web Page - Computer Hope
Perform Google search · Paste what you copied into a Google search, or the omnibox at the top of your browser, and then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found