Skip to content

Commit

Permalink
chore: Go for the official tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Jan 27, 2024
1 parent f731ea0 commit c8baa72
Showing 1 changed file with 1 addition and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { CodeBlock } from '@/src/components/code-block'
import { FileCode2 } from 'lucide-react'
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'url'

type SourceOnGitHubProps = {
path: string
Expand Down Expand Up @@ -32,25 +30,7 @@ export async function SourceOnGitHub({ path }: SourceOnGitHubProps) {
}

function readSourceCode(demoPath: string) {
const demoFilePath = resolve(import.meta.url, '..', demoPath)
const demoFilePath = process.cwd() + '/src/app/playground/(demos)/' + demoPath
console.log(demoFilePath)
return fs.readFile(demoFilePath, 'utf8')
}

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const nextJsRootDir = path.resolve(__dirname, '../../../../..')

function resolve(importMetaUrl: string, ...paths: string[]) {
const filePath = fileURLToPath(importMetaUrl)
const dirname = path.dirname(filePath)
const fileName = path.basename(filePath)
const absPath = path.resolve(
dirname,
// This makes sure that if only the import.meta.url is passed,
// we resolve to the same file. Otherwise, allow relative paths.
...(paths.length === 0 ? [fileName] : paths)
)
// Required for ISR serverless functions to pick up the file path
// as a dependency to bundle.
return path.resolve(process.cwd(), absPath.replace(nextJsRootDir, '.'))
}

0 comments on commit c8baa72

Please sign in to comment.