Skip to content

Commit

Permalink
Add link to source for block reference (#37750)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaz committed Jan 6, 2022
1 parent 7a8d9fa commit fd9aef8
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 90 deletions.
17 changes: 16 additions & 1 deletion bin/api-docs/gen-block-lib-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ function augmentSupports( supports ) {
return supports;
}

/**
* Returns URL to the block directory source.
*
* @param {string} filename
*
* @return {string} URL
*/
function getSourceFromFile( filename ) {
const pkgdir =
'https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/';
const blockdir = path.basename( path.dirname( filename ) );
return pkgdir + blockdir;
}

/**
* Reads block.json file and returns markdown formatted entry.
*
Expand All @@ -132,14 +146,15 @@ function augmentSupports( supports ) {
function readBlockJSON( filename ) {
const blockjson = require( filename );

const sourcefile = getSourceFromFile( filename );
const supportsAugmented = augmentSupports( blockjson.supports );
const supportsList = processObjWithInnerKeys( supportsAugmented );
const attributes = getTruthyKeys( blockjson.attributes );

return `
## ${ blockjson.title }
${ blockjson.description }
${ blockjson.description } ([Source](${ sourcefile }))
- **Name:** ${ blockjson.name }
- **Category:** ${ blockjson.category }
Expand Down
Loading

0 comments on commit fd9aef8

Please sign in to comment.