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

Remove initial time since and add link to file history #257

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions src/layouts/MainLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ const currentPage = Astro.url.pathname + '/'
const filePath = Astro.props.frontmatter.filePath
const currentFile = filePath?.replace(/.*src/, 'src')
const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`
const githubCommitsUrl = githubEditUrl.replace('tree', 'commits')
const lastModified = Astro.props.frontmatter.lastModified
const updatedSince = timeSince(
new Date(lastModified?.toString() || '')
).replace(',', ' and')
---

<html
Expand Down Expand Up @@ -233,10 +231,9 @@ const updatedSince = timeSince(
headings={headings}
githubEditUrl={githubEditUrl}
>
<p class='text-theme-muted'>
Last updated <span id="update-time" data-timestamp={lastModified}>{updatedSince}</span> ago <span
class='text-sm text-theme-muted/30 italic'
Comment on lines -237 to -238
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial value was incorrect, because it was generating a timestamp of the server build time, instead of current date

>
<a href={githubCommitsUrl} target='_blank' class='text-theme-muted'>
Last updated <span id='update-time' data-timestamp={lastModified}
></span> ago <span class='text-sm text-theme-muted/30 italic'>
- {
new Date(lastModified || '').toLocaleDateString('en-EN', {
month: 'long',
Expand All @@ -245,7 +242,7 @@ const updatedSince = timeSince(
})
}
</span>
</p>
</a>
<slot />
</PageContent>
<RecommendedSections />
Expand All @@ -257,26 +254,25 @@ const updatedSince = timeSince(
<Footer isDocs />
<CopyCodeToClipboard />
<HeadingLinksCopyToClipboard />
</body>
</html>
<script>
import { timeSince } from '../utils/timeSince'

<script>
import { timeSince } from '../utils/timeSince'

const setCurrentTimeSince = () => {
const updateTime = document.getElementById('update-time')
if (updateTime) {
const timestamp = updateTime.getAttribute('data-timestamp')
if(timestamp === null) return
const date = new Date(timestamp)
const newTimeSince = timeSince(date).replace(',', ' and')
updateTime.innerText = newTimeSince
}
}
const setCurrentTimeSince = () => {
const updateTime = document.getElementById('update-time')
if (updateTime) {
const timestamp = updateTime.getAttribute('data-timestamp')
if (timestamp === null) return
const date = new Date(timestamp)
const newTimeSince = timeSince(date).replace(',', ' and')
updateTime.innerText = newTimeSince
}
}

setCurrentTimeSince()
setCurrentTimeSince()

setInterval(() => {
setCurrentTimeSince()
}, 1000)
</script>
setInterval(() => {
setCurrentTimeSince()
}, 1000)
</script>
</body>
</html>
Loading