Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

indexing - GitHub - Remove a indexed file from "Languages" on first page

How can I remove this indexed HTML page, that are a documentation to one of the external librarys I use on my GitHub blob?

I have tried alot of diffrent commands, but don't find a way to remove this file from the GitHub Linguist indexer...

Here are the "Languages" that are indexed on the startpage: [image] Languages on the startpage

The file that I want to exclude: [image] HTML file that needs to be excluded

TestProject/wwwroot/lib/bootstrap-icons/docs/index.html

Code that I've tried to get it removed via ".attributes"-file in root-folder (the vendored, works... But not getting rid of this HTML-file... from the GitHub-Languages) :

### vendored:
TestProject/wwwroot/lib/* linguist-vendored

### documentations:
TestProject/wwwroot/lib/bootstrap-icons/* linguist-documentation

and tried:

TestProject/wwwroot/lib/bootstrap-icons/* -linguist-documentation

and this:

TestProject/wwwroot/lib/bootstrap-icons/docs/* linguist-documentation

and this:

TestProject/wwwroot/lib/bootstrap-icons/docs/* -linguist-documentation

and this:

TestProject/wwwroot/lib/* linguist-documentation

and this:

TestProject/wwwroot/lib/* -linguist-documentation

But I can't figure it out how to remove this file:

TestProject/wwwroot/lib/bootstrap-icons/docs/index.html

Please help me with the correct syntax to remove the file from being indexed as a Language in my GitHub repository, main branch. ??

question from:https://stackoverflow.com/questions/65905812/github-remove-a-indexed-file-from-languages-on-first-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You've got the right idea and the right Linguist overrides (either will do the trick). The problem is your path matching isn't quite right.

From the .gitattributes docs

The rules by which the pattern matches paths are the same as in .gitignore files (see gitignore[5]), with a few exceptions: [...]

If we look in the .gitignore docs (emphasis is mine):

An asterisk "*" matches anything except a slash. The character "?" matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.

Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning: [...]

  • A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.

The files you're trying to ignore are in sub-directories of the paths you've specified so you need to either:

  • use TestProject/wwwroot/lib/** linguist-vendored to recurse, or
  • use TestProject/wwwroot/lib/bootstrap-icons/docs/* linguist-vendored to limit to this directory.

We can demonstrate this without even using Linguist thanks to git check-attr:

$ # Create a repo with just the one file
$ git init -q Test-Project
$ cd Test-Project
$ mkdir -p TestProject/wwwroot/lib/bootstrap-icons/docs/
$ echo "<html>" > TestProject/wwwroot/lib/bootstrap-icons/docs/index.html
$ git add -A
$ git commit -m 'Add file'
[main (root-commit) bed71b5] Add file
 1 file changed, 1 insertion(+)
 create mode 100644 TestProject/wwwroot/lib/bootstrap-icons/docs/index.html
$
$ # Add your initial override
$ git add -A && git commit -m 'attribs'
[main 7d0a0cf] attribs
 1 file changed, 1 insertion(+)
 create mode 100644 .gitattributes
$
$ # Check the attributes
$ git check-attr linguist-vendored TestProject/wwwroot/lib/bootstrap-icons/docs/index.html
TestProject/wwwroot/lib/bootstrap-icons/docs/index.html: linguist-vendored: unspecified
$ # So it doesn't have any effect.
$ # Now lets recurse
$ echo "TestProject/wwwroot/lib/** linguist-vendored" > .gitattributes
$ git add -A && git commit -m 'attribs'
[main 9007c34] attribs
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git check-attr linguist-vendored TestProject/wwwroot/lib/bootstrap-icons/docs/index.html
TestProject/wwwroot/lib/bootstrap-icons/docs/index.html: linguist-vendored: set
$ # Woohoo!!! It's work. 
$ # Lets be specific to the docs dir
$ echo "TestProject/wwwroot/lib/bootstrap-icons/docs/* linguist-vendored" > .gitattributes
$ git add -A && git commit -m 'attribs'
[main a46f416] attribs
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git check-attr linguist-vendored TestProject/wwwroot/lib/bootstrap-icons/docs/index.html
TestProject/wwwroot/lib/bootstrap-icons/docs/index.html: linguist-vendored: set
$ # Woohoo!!! It's worked too

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...